Horizon是OpenStack的Web界面工程,使用Python世界的MVC框架Django书写。
工欲善其事,必先利其器。本文将描述如何使用pydev插件在eclipse中调试horizon,这将极大提高开发效率。步骤很简单,分享如下:

1, 为eclipse安装pydev插件,略;
2, 假设horizon的代码通过git下载到了/opt/stack/horizon目录下,那么将eclipse的workspace切换到/opt/stack目录下;
3, 新建名为horizon的pydev类型的工程(菜单File -> New -> PyDev Project),填写工程名之后直接按”Finish”键完成即可;
4, 将/opt/stack/horizon/manage.py文件用下面内容替换;
#!/usr/bin/env python

import os
import sys
from django.core.management import execute_manager

ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
if ROOT_PATH not in sys.path:
sys.path.insert(0,ROOT_PATH)
import openstack_dashboard.settings

if __name__ == “__main__”:
os.environ['DJANGO_SETTINGS_MODULE'] = ‘openstack_dashboard.settings’
execute_manager(openstack_dashboard.settings)
5, 在eclipse中以debug模式加参数“runserver –noreload”运行manage.py即可调试了。

文章来源:原创
文章作者:Joshua, OpenStack中国社区

  1. 上面的问题已经解决:horizon/openstack_dashboard/local/local_settings.py.example 更名为horizon/openstack_dashboard/local/local_settings.pymanage.py 不用修改 ,在pyCharm 配置run就可以了 注意安装依赖 pip install -r requirements.txt 如果依赖有问题或horizon报错可以用下面命令排查python manage.py compress

    • 请问下,我在git上把horizon clone 下来之后,进入到horizon目录下运行:python manage.py runserver提示如下错误:ImportError: Could not import settings ‘openstack_dashboard.settings’ (Is it on sys.path? Is there an import error in the settings file?): No module named cinderclient。还有请问下,直接只是单独地下载了openstack中的horizon,可以进行horizon的调试吗?

    • 我排查后出现这个错误求解决Traceback (most recent call last): File “manage.py”, line 24, in execute_from_command_line(sys.argv) File “D:Python27libsite-packagesdjangocoremanagement__init__.py”, line 354, in execute_from_command_line utility.execute() File “D:Python27libsite-packagesdjangocoremanagement__init__.py”, line 328, in execute django.setup() File “D:Python27libsite-packagesdjango__init__.py”, line 18, in setup apps.populate(settings.INSTALLED_APPS) File “D:Python27libsite-packagesdjangoappsregistry.py”, line 85, in populate app_config = AppConfig.create(entry) File “D:Python27libsite-packagesdjangoappsconfig.py”, line 86, in create module = import_module(entry) File “D:Python27libimportlib__init__.py”, line 37, in import_module __import__(name)ImportError: No module named compressor

  2. 按照文档执行后run或者debug报错,求教,还有那些地方需要配置?/usr/bin/python2.7 /home/work/xiangcloud/horizon-2015.1.0b1/manage.py runserver –noreloadTraceback (most recent call last): File “/home/work/xiangcloud/horizon-2015.1.0b1/manage.py”, line 26, in from openstack_dashboard import settings File “/home/work/xiangcloud/horizon-2015.1.0b1/openstack_dashboard/settings.py”, line 345, in from openstack_dashboard import policy File “/home/work/xiangcloud/horizon-2015.1.0b1/openstack_dashboard/policy.py”, line 22, in from openstack_auth import utils as auth_utils File “/usr/lib/python2.7/dist-packages/openstack_auth/utils.py”, line 20, in from django.contrib import auth File “/usr/local/lib/python2.7/dist-packages/django/contrib/auth/__init__.py”, line 5, in from django.middleware.csrf import rotate_token File “/usr/local/lib/python2.7/dist-packages/django/middleware/csrf.py”, line 16, in from django.utils.cache import patch_vary_headers File “/usr/local/lib/python2.7/dist-packages/django/utils/cache.py”, line 26, in from django.core.cache import get_cache File “/usr/local/lib/python2.7/dist-packages/django/core/cache/__init__.py”, line 70, in if DEFAULT_CACHE_ALIAS not in settings.CACHES: File “/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py”, line 53, in __getattr__ self._setup(name) File “/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py”, line 46, in _setup % (desc, ENVIRONMENT_VARIABLE))django.core.exceptions.ImproperlyConfigured: Requested setting CACHES, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.Process finished with exit code 1