Eclipse 中的 Django Shell 未启动

Django Shell in Eclipse not starting

当我尝试从 Eclipse Neon 运行 shell 时收到此错误消息,而我可以从命令 [=24] 成功 运行 Django shell =].我正在使用 Python 3.4 和 Django 1.10。知道问题出在哪里吗?

WSGI 文件:

'''
WSGI config for MyProject project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/1.10/howto/deployment/wsgi/
'''

import os
from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "MyProject.settings")

application = get_wsgi_application()

我相信这是 Eclipse Pydev 中的一个已知错误。

https://www.brainwy.com/tracker/PyDev

Fixed for 5.6

Git: 2c8cd03 2017-03-12 Fabio Zadrozny #PyDev-752: Django version not detected if > 1.10

并且已经发布了修复程序。

您可以尝试正常启动 python shell,然后:

import sys; print('%s %s' % (sys.executable or sys.platform, sys.version))
import os; os.environ['DJANGO_SETTINGS_MODULE'] = '<Project Name>.settings'; import django
sys.path.append(os.path.expanduser('<path to your project>'))
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

将 'Project Name' 替换为您的项目名称,并将 'path to your project' 替换为您的路径

或者,使用 1.10 之前的 Django 版本,即 1.7