Python 从Django站点尝试教程时出现AppRegistryNotReady错误
我正在尝试Django网站上提供的教程。当我试图在命令下运行时,我遇到了错误Python 从Django站点尝试教程时出现AppRegistryNotReady错误,python,django,Python,Django,我正在尝试Django网站上提供的教程。当我试图在命令下运行时,我遇到了错误 q = Question.objects.get(pk=1) q.choice_set.all() Traceback (most recent call last): File "<input>", line 1, in <module> File "C:\Python27\lib\site-packages\django\db\models\manager.py", line 228
q = Question.objects.get(pk=1)
q.choice_set.all()
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Python27\lib\site-packages\django\db\models\manager.py", line 228, in all
return self.get_queryset()
File "C:\Python27\lib\site-packages\django\db\models\fields\related.py", line 706, in get_queryset
qs = qs.filter(**self.core_filters)
File "C:\Python27\lib\site-packages\django\db\models\query.py", line 679, in filter
return self._filter_or_exclude(False, *args, **kwargs)
File "C:\Python27\lib\site-packages\django\db\models\query.py", line 697, in _filter_or_exclude
clone.query.add_q(Q(*args, **kwargs))
File "C:\Python27\lib\site-packages\django\db\models\sql\query.py", line 1304, in add_q
clause, require_inner = self._add_q(where_part, self.used_aliases)
File "C:\Python27\lib\site-packages\django\db\models\sql\query.py", line 1332, in _add_q
allow_joins=allow_joins, split_subq=split_subq,
File "C:\Python27\lib\site-packages\django\db\models\sql\query.py", line 1144, in build_filter
lookups, parts, reffed_aggregate = self.solve_lookup_type(arg)
File "C:\Python27\lib\site-packages\django\db\models\sql\query.py", line 1030, in solve_lookup_type
_, field, _, lookup_parts = self.names_to_path(lookup_splitted, self.get_meta())
File "C:\Python27\lib\site-packages\django\db\models\sql\query.py", line 1367, in names_to_path
if field.is_relation and not field.related_model:
File "C:\Python27\lib\site-packages\django\utils\functional.py", line 60, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Python27\lib\site-packages\django\db\models\fields\related.py", line 110, in related_model
apps.check_models_ready()
File "C:\Python27\lib\site-packages\django\apps\registry.py", line 131, in check_models_ready
raise AppRegistryNotReady("Models aren't loaded yet.")
AppRegistryNotReady: Models aren't loaded yet.
这是我的manage.py代码
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "demo.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
这是我的wsgi文件
"""
WSGI config for demo 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.8/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "demo.settings")
application = get_wsgi_application()
我不确定我到底做错了什么。我遵循了教程,但它在这里中断
我正在使用python 2.7.9和Django 1.8.2在哪里运行代码?您是否使用
manage.py shell
启动加载了django的python shell?显示您的wsgi文件,我认为它或您的manage有问题。pyI仅使用manage.py shell(使用pydev)运行我的代码。我不熟悉pydevmanage.py shell
应该为您运行django.setup()
。您可以尝试手动执行此操作<代码>导入django;django.setup()以查看是否已修复。您在哪里运行代码?您是否使用manage.py shell
启动加载了django的python shell?显示您的wsgi文件,我认为它或您的manage有问题。pyI仅使用manage.py shell(使用pydev)运行我的代码。我不熟悉pydevmanage.py shell
应该为您运行django.setup()
。您可以尝试手动执行此操作<代码>导入django;django.setup()以查看这是否可以修复它。
"""
WSGI config for demo 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.8/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "demo.settings")
application = get_wsgi_application()