在eclipse中通过pydev集成django ?

时间:2021-05-02 19:19:00

I have installed eclipse indigo and pydev and python 32.

我已经安装了eclipse indigo、pydev和python 32。

I have configured my python path and can create an "empty" django project:

我已经配置了我的python路径,可以创建一个“空的”django项目:

在eclipse中通过pydev集成django ?

However, when I run right click on project and run as->pydev: django

但是,当我运行项目时,右键单击项目并以->pydev: django的形式运行

I get:

我得到:

Traceback (most recent call last):
  File "C:\Users\djangoworkspace\test3\src\manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 443, in execute_from_command_line
    utility.execute()
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 382, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 261, in fetch_command
    klass = load_command_class(app_name, subcommand)
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 69, in load_command_class
    module = import_module('%s.management.commands.%s' % (app_name, name))
  File "C:\Python27\lib\site-packages\django\utils\importlib.py", line 35, in import_module
    __import__(name)
  File "C:\Python27\lib\site-packages\django\core\management\commands\runserver.py", line 8, in <module>
    from django.core.servers.basehttp import AdminMediaHandler, run, WSGIServerException, get_internal_wsgi_application
  File "C:\Python27\lib\site-packages\django\core\servers\basehttp.py", line 26, in <module>
    from django.views import static
  File "C:\Python27\lib\site-packages\django\views\static.py", line 95, in <module>
    template_translatable = ugettext_noop(u"Index of %(directory)s")
  File "C:\Python27\lib\site-packages\django\utils\translation\__init__.py", line 75, in gettext_noop
    return _trans.gettext_noop(message)
  File "C:\Python27\lib\site-packages\django\utils\translation\__init__.py", line 48, in __getattr__
    if settings.USE_I18N:
  File "C:\Python27\lib\site-packages\django\utils\functional.py", line 184, in inner
    self._setup()
  File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 42, in _setup
    self._wrapped = Settings(settings_module)
  File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 95, in __init__
    raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
ImportError: Could not import settings 'C:\Python27\Lib\site-packages\django\conf\project_template\settings.py' (Is it on sys.path?): Import by filename is not supported.

Any idea what I ned to fix to run a django project in eclipse?

您知道在eclipse中运行django项目需要修复什么吗?

3 个解决方案

#1


5  

Be sure to follow these steps from http://pydev.org/manual_adv_django.html

请务必遵循以下步骤:http://pydev.org/manual_adv_django.html。

  1. The project must be marked as a Django project inside of PyDev.

    项目必须标记为PyDev中的Django项目。

  2. A DJANGO_MANAGE_LOCATION string substitution variable must point to the project-relative location of manage.py.

    DJANGO_MANAGE_LOCATION字符串替换变量必须指向manage.py的项目相关位置。

  3. A DJANGO_SETTINGS_MODULE string substitution variable must contain the name of the settings module in that project.

    DJANGO_SETTINGS_MODULE字符串替换变量必须包含项目中设置模块的名称。

DJANGO_SETTINGS_MODULE is actually python module name, not a specific file. So your DJANGO_SETTINGS_MODULE should be 'project_template.settings'

DJANGO_SETTINGS_MODULE实际上是python模块名,而不是特定的文件。所以DJANGO_SETTINGS_MODULE应该是" project_template.settings "

#2


4  

Right click on the project and select 'Pydev-Django' and the following

右键单击项目并选择“Pydev-Django”和以下内容

  1. 'Django manage.py': this is relative path to the manage.py file with respect to the project root
  2. Django的管理。这是管理的相对路径。py文件关于项目根
  3. 'Django settings module:' this is python dotted path to the setting file being used (exclude .py) as shown below 在eclipse中通过pydev集成django ?
  4. 'Django设置模块:'这是要使用的设置文件的python点路径(排除.py),如下所示

if you see the message " Module: x.x.setting could be found" as in the picture above then add this project to the python path as show below

如果您看到消息“模块:x.x。可以找到“设置”,如上图所示,然后将此项目添加到python路径中,如下所示

right click the project and select Pydev - PYTHONPATH

右键单击项目并选择Pydev - PYTHONPATH

在eclipse中通过pydev集成django ?

now python project is added

现在添加了python项目

在eclipse中通过pydev集成django ?

After adding python path to the project settings module is found 在eclipse中通过pydev集成django ?

在将python路径添加到项目设置模块之后,将找到它

Everything will fine now :) note: This was made using django 1.10 and pydev 5.2

注意:这是使用django 1.10和pydev 5.2制作的

#3


3  

  • Go to Window -> Preferences -> Pydev -> Interpreter - Python
  • 转到窗口->首选项-> Pydev ->解释器- Python
  • Go to the String Substitution Variables tab
  • 转到字符串替换变量选项卡
  • Add the 2 following variables:
    • DJANGO_MANAGE_LOCATION with the path to django/conf/project_template/
    • DJANGO_MANAGE_LOCATION具有到django/conf/project_template/的路径
    • DJANGO_SETTINGS_MODULE with the /settings/
    • DJANGO_SETTINGS_MODULE /设置/
  • 添加以下两个变量:DJANGO_MANAGE_LOCATION,其路径为django/conf/project_template/ DJANGO_SETTINGS_MODULE和/settings/

#1


5  

Be sure to follow these steps from http://pydev.org/manual_adv_django.html

请务必遵循以下步骤:http://pydev.org/manual_adv_django.html。

  1. The project must be marked as a Django project inside of PyDev.

    项目必须标记为PyDev中的Django项目。

  2. A DJANGO_MANAGE_LOCATION string substitution variable must point to the project-relative location of manage.py.

    DJANGO_MANAGE_LOCATION字符串替换变量必须指向manage.py的项目相关位置。

  3. A DJANGO_SETTINGS_MODULE string substitution variable must contain the name of the settings module in that project.

    DJANGO_SETTINGS_MODULE字符串替换变量必须包含项目中设置模块的名称。

DJANGO_SETTINGS_MODULE is actually python module name, not a specific file. So your DJANGO_SETTINGS_MODULE should be 'project_template.settings'

DJANGO_SETTINGS_MODULE实际上是python模块名,而不是特定的文件。所以DJANGO_SETTINGS_MODULE应该是" project_template.settings "

#2


4  

Right click on the project and select 'Pydev-Django' and the following

右键单击项目并选择“Pydev-Django”和以下内容

  1. 'Django manage.py': this is relative path to the manage.py file with respect to the project root
  2. Django的管理。这是管理的相对路径。py文件关于项目根
  3. 'Django settings module:' this is python dotted path to the setting file being used (exclude .py) as shown below 在eclipse中通过pydev集成django ?
  4. 'Django设置模块:'这是要使用的设置文件的python点路径(排除.py),如下所示

if you see the message " Module: x.x.setting could be found" as in the picture above then add this project to the python path as show below

如果您看到消息“模块:x.x。可以找到“设置”,如上图所示,然后将此项目添加到python路径中,如下所示

right click the project and select Pydev - PYTHONPATH

右键单击项目并选择Pydev - PYTHONPATH

在eclipse中通过pydev集成django ?

now python project is added

现在添加了python项目

在eclipse中通过pydev集成django ?

After adding python path to the project settings module is found 在eclipse中通过pydev集成django ?

在将python路径添加到项目设置模块之后,将找到它

Everything will fine now :) note: This was made using django 1.10 and pydev 5.2

注意:这是使用django 1.10和pydev 5.2制作的

#3


3  

  • Go to Window -> Preferences -> Pydev -> Interpreter - Python
  • 转到窗口->首选项-> Pydev ->解释器- Python
  • Go to the String Substitution Variables tab
  • 转到字符串替换变量选项卡
  • Add the 2 following variables:
    • DJANGO_MANAGE_LOCATION with the path to django/conf/project_template/
    • DJANGO_MANAGE_LOCATION具有到django/conf/project_template/的路径
    • DJANGO_SETTINGS_MODULE with the /settings/
    • DJANGO_SETTINGS_MODULE /设置/
  • 添加以下两个变量:DJANGO_MANAGE_LOCATION,其路径为django/conf/project_template/ DJANGO_SETTINGS_MODULE和/settings/