Python Django在eclipse中没有名为app的模块

时间:2017-02-10 14:28:38

标签: python django eclipse migration

我刚刚在eclipse中制作了第一个django项目。我创建了一个应用程序并且做了迁移'所以在admin中创建表但收到此错误消息。

Traceback (most recent call last):
File "C:\Users\jeon hyun joo\workspace\blog\blog\manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "C:\Python27\lib\site-packages\django-1.10.5-py2.7.egg\django\core\management\__init__.py", line 367, in execute_from_command_line
utility.execute()
File "C:\Python27\lib\site-packages\django-1.10.5-py2.7.egg\django\core\management\__init__.py", line 341, in execute
django.setup()
File "C:\Python27\lib\site-packages\django-1.10.5-py2.7.egg\django\__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Python27\lib\site-packages\django-1.10.5-py2.7.egg\django\apps\registry.py", line 115, in populate
app_config.ready()
File "C:\Python27\lib\site-packages\django-1.10.5-py2.7.egg\django\contrib\admin\apps.py", line 23, in ready
self.module.autodiscover()
File "C:\Python27\lib\site-packages\django-1.10.5-py2.7.egg\django\contrib\admin\__init__.py", line 26, in autodiscover
autodiscover_modules('admin', register_to=site)
File "C:\Python27\lib\site-packages\django-1.10.5-py2.7.egg\django\utils\module_loading.py", line 50, in autodiscover_modules
import_module('%s.%s' % (app_config.name, module_to_search))
File "C:\Python27\lib\importlib\__init__.py", line 37, in import_module
__import__(name)
File "C:\Users\jeon hyun joo\workspace\blog\blog\polls\admin.py", line 2, in <module>
from blog.polls.models import Question, Choice
ImportError: No module named polls.models
Finished "C:\Users\jeon hyun joo\workspace\blog\blog\manage.py makemigrations polls" execution.

我在settings.py

中注册了应用
# Application definition

INSTALLED_APPS = [
   'django.contrib.admin',
   'django.contrib.auth',
   'django.contrib.contenttypes',
   'django.contrib.sessions',
   'django.contrib.messages',
   'django.contrib.staticfiles',
     'polls'
    ]

并且每个包中都有 init.py 文件。 我在这个项目中做的是创建一个应用程序并编辑models.py和admin.py。我还没有创建任何其他文件。我该怎么做才能解决这个问题?

我添加了urls.py

from django.conf.urls import url
from django.contrib import admin

urlpatterns = [
    url(r'^admin/', admin.site.urls),
]

1 个答案:

答案 0 :(得分:0)

我猜您正尝试在管理页面中注册您的模型。尝试两件事,

  1. 尝试更改导入语句,如

    from .models import Question, Choice
    #or
    from polls.models import Question, Choice
    
  2. blog

  3. 添加(明确)polls以及PYTHONPATH
  4. 注释导致迁移问题的代码,例如,注释掉您的导入(这将导致您注释掉其他行)。继续为所有未能迁移的行执行此操作。