This is the traceback on my windows system.
这是我的windows系统的traceback。
Traceback (most recent call last):
File "D:\AMD\workspace\steelrumors\manage.py", line 9, in <module>
django.setup()
File "D:\AMD\Django\django-django-4c85a0d\django\__init__.py", line 21, in setup
apps.populate(settings.INSTALLED_APPS)
File "D:\AMD\Django\django-django-4c85a0d\django\apps\registry.py", line 108, in populate
app_config.import_models(all_models)
File "D:\AMD\Django\django-django-4c85a0d\django\apps\config.py", line 197, in import_models
self.models_module = import_module(models_module_name)
File "C:\Python27\lib\importlib\__init__.py", line 37, in import_module
__import__(name)
File "C:\Python27\lib\site-packages\registration\models.py", line 15, in <module>
User = get_user_model()
File "D:\AMD\Django\django-django-4c85a0d\django\contrib\auth\__init__.py", line 135, in get_user_model
return django_apps.get_model(settings.AUTH_USER_MODEL)
File "D:\AMD\Django\django-django-4c85a0d\django\apps\registry.py", line 199, in get_model
self.check_models_ready()
File "D:\AMD\Django\django-django-4c85a0d\django\apps\registry.py", line 131, in check_models_ready
raise AppRegistryNotReady("Models aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.
And my manage.py looks like this:
我的管理。py是这样的:
import os
import sys
import django
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "steelrumors.settings")
django.setup()
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
I get this error when i am trying to use registration app in Django 1.7
当我试图在Django 1.7中使用注册应用程序时,我得到了这个错误。
10 个解决方案
#1
55
This is what solved it for us and these folks:
这是为我们和这些人解决的问题:
Our project started with Django 1.4, we went to 1.5 and then to 1.7. Our wsgi.py looked like this:
我们的项目从Django 1.4开始,到1.5,然后到1.7。我们的wsgi。py看起来像这样:
import os
from django.core.handlers.wsgi import WSGIHandler
os.environ['DJANGO_SETTINGS_MODULE'] = 'myapp.settings'
application = WSGIHandler()
When I updated to the 1.7 style WSGI handler:
当我更新到1.7风格的WSGI处理器:
import os
from django.core.wsgi import get_wsgi_application
os.environ['DJANGO_SETTINGS_MODULE'] = 'myapp.settings'
application = get_wsgi_application()
Everything works now.
现在一切正常。
#2
223
Running these commands solved my problem (credit to this answer):
运行这些命令解决了我的问题(归功于这个答案):
import django
django.setup()
However I'm not sure why I need this. Comments would be appreciated.
但是我不知道为什么我需要这个。评论将不胜感激。
#3
55
The issue is in your registration app. It seems django-registration calls get_user_module()
in models.py
at a module level (when models are still being loaded by the application registration process). This will no longer work:
这个问题出现在你的注册应用程序中,看起来django注册在模型中调用get_user_module()。在模块级别上的py(当模型仍然被应用程序注册过程加载时)。这将不再起作用:
try:
from django.contrib.auth import get_user_model
User = get_user_model()
except ImportError:
from django.contrib.auth.models import User
I'd change this models file to only call get_user_model()
inside methods (and not at module level) and in FKs use something like:
我将把这个模型文件改为只调用get_user_model()内部方法(而不是在模块级别),而在FKs中使用一些类似的东西:
user = ForeignKey(settings.AUTH_USER_MODEL)
BTW, the call to django.setup()
shouldn't be required in your manage.py
file, it's called for you in execute_from_command_line
. (source)
在您的管理中不应该要求设置()。py文件,在execute_from_command_line中调用它。(源)
#4
19
Just encountered the same issue. The problem is because of django-registration
incompatible with django 1.7 user model.
只是遇到了同样的问题。问题在于django-registration与django 1.7用户模型不兼容。
A simple fix is to change these lines of code, at your installed django-registration
module::
一个简单的解决方法是修改这些代码行,在您安装的django-registration模块中::
try:
from django.contrib.auth import get_user_model
User = get_user_model()
except ImportError:
from django.contrib.auth.models import User
to::
::
from django.conf import settings
try:
from django.contrib.auth import get_user_model
User = settings.AUTH_USER_MODEL
except ImportError:
from django.contrib.auth.models import User
Mine is at .venv/local/lib/python2.7/site-packages/registration/models.py
(virtualenv)
我在当地.venv / / lib / python2.7 /网站/注册/模型。py(virtualenv)
#5
10
This works for me for Django 1.9 . The Python script to execute was in the root of the Django project.
这对我来说对Django 1.9很有用。执行的Python脚本是Django项目的根。
import django
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "PROJECT_NAME.settings")
django.setup()
from APP_NAME.models import *
Set PROJECT_NAME and APP_NAME to yours
将PROJECT_NAME和APP_NAME设置为您的。
#6
5
Another option is that you have a duplicate entry in INSTALLED_APPS. That threw this error for two different apps I tested. Apparently it's not something Django checks for, but then who's silly enough to put the same app in the list twice. Me, that's who.
另一个选项是在INSTALLED_APPS中有一个重复的条目。这为我测试的两个不同的应用程序提供了这个错误。很显然,这不是Django检查的东西,但是谁傻到把同一个应用程序放在列表中两次。我,这是谁。
#7
2
Do you have a Python virtual environment that you need to enter before you run manage.py?
在运行manage.py之前,是否有需要输入的Python虚拟环境?
I ran into this error myself, and that was the problem.
我自己也遇到了这个错误,这就是问题所在。
#8
2
I ran into this issue when I use djangocms and added a plugin (in my case: djangocms-cascade). Of course I had to add the plugin to the INSTALLED_APPS. But the order is here important.
我在使用djangocms时遇到了这个问题,并添加了一个插件(在我的例子中是djangocms-cascade)。当然,我必须将插件添加到INSTALLED_APPS中。但这里的秩序很重要。
To place 'cmsplugin_cascade' before 'cms' solved the issue.
将cmsplugin_cascade放在“cms”解决问题之前。
#9
2
install django-registration-redux==1.1 instead django-registration, if you using django 1.7
如果使用django 1.7,安装django-registration-redux==1.1,而不是django注册。
#10
-1
Your manage.py
is "wrong"; I don't know where you got it from, but that's not a 1.7 manage.py
- were you using some funky pre-release build or something?
你的管理。py是“错误的”;我不知道你从哪里得到的,但这不是一个1.7。py -你使用了一些时髦的预发布版本吗?
Reset your manage.py
to the conventional, as below, and things Should Just Work:
重设你的管理。py与常规,如下所示,一切都应该工作:
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "{{ project_name }}.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
#1
55
This is what solved it for us and these folks:
这是为我们和这些人解决的问题:
Our project started with Django 1.4, we went to 1.5 and then to 1.7. Our wsgi.py looked like this:
我们的项目从Django 1.4开始,到1.5,然后到1.7。我们的wsgi。py看起来像这样:
import os
from django.core.handlers.wsgi import WSGIHandler
os.environ['DJANGO_SETTINGS_MODULE'] = 'myapp.settings'
application = WSGIHandler()
When I updated to the 1.7 style WSGI handler:
当我更新到1.7风格的WSGI处理器:
import os
from django.core.wsgi import get_wsgi_application
os.environ['DJANGO_SETTINGS_MODULE'] = 'myapp.settings'
application = get_wsgi_application()
Everything works now.
现在一切正常。
#2
223
Running these commands solved my problem (credit to this answer):
运行这些命令解决了我的问题(归功于这个答案):
import django
django.setup()
However I'm not sure why I need this. Comments would be appreciated.
但是我不知道为什么我需要这个。评论将不胜感激。
#3
55
The issue is in your registration app. It seems django-registration calls get_user_module()
in models.py
at a module level (when models are still being loaded by the application registration process). This will no longer work:
这个问题出现在你的注册应用程序中,看起来django注册在模型中调用get_user_module()。在模块级别上的py(当模型仍然被应用程序注册过程加载时)。这将不再起作用:
try:
from django.contrib.auth import get_user_model
User = get_user_model()
except ImportError:
from django.contrib.auth.models import User
I'd change this models file to only call get_user_model()
inside methods (and not at module level) and in FKs use something like:
我将把这个模型文件改为只调用get_user_model()内部方法(而不是在模块级别),而在FKs中使用一些类似的东西:
user = ForeignKey(settings.AUTH_USER_MODEL)
BTW, the call to django.setup()
shouldn't be required in your manage.py
file, it's called for you in execute_from_command_line
. (source)
在您的管理中不应该要求设置()。py文件,在execute_from_command_line中调用它。(源)
#4
19
Just encountered the same issue. The problem is because of django-registration
incompatible with django 1.7 user model.
只是遇到了同样的问题。问题在于django-registration与django 1.7用户模型不兼容。
A simple fix is to change these lines of code, at your installed django-registration
module::
一个简单的解决方法是修改这些代码行,在您安装的django-registration模块中::
try:
from django.contrib.auth import get_user_model
User = get_user_model()
except ImportError:
from django.contrib.auth.models import User
to::
::
from django.conf import settings
try:
from django.contrib.auth import get_user_model
User = settings.AUTH_USER_MODEL
except ImportError:
from django.contrib.auth.models import User
Mine is at .venv/local/lib/python2.7/site-packages/registration/models.py
(virtualenv)
我在当地.venv / / lib / python2.7 /网站/注册/模型。py(virtualenv)
#5
10
This works for me for Django 1.9 . The Python script to execute was in the root of the Django project.
这对我来说对Django 1.9很有用。执行的Python脚本是Django项目的根。
import django
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "PROJECT_NAME.settings")
django.setup()
from APP_NAME.models import *
Set PROJECT_NAME and APP_NAME to yours
将PROJECT_NAME和APP_NAME设置为您的。
#6
5
Another option is that you have a duplicate entry in INSTALLED_APPS. That threw this error for two different apps I tested. Apparently it's not something Django checks for, but then who's silly enough to put the same app in the list twice. Me, that's who.
另一个选项是在INSTALLED_APPS中有一个重复的条目。这为我测试的两个不同的应用程序提供了这个错误。很显然,这不是Django检查的东西,但是谁傻到把同一个应用程序放在列表中两次。我,这是谁。
#7
2
Do you have a Python virtual environment that you need to enter before you run manage.py?
在运行manage.py之前,是否有需要输入的Python虚拟环境?
I ran into this error myself, and that was the problem.
我自己也遇到了这个错误,这就是问题所在。
#8
2
I ran into this issue when I use djangocms and added a plugin (in my case: djangocms-cascade). Of course I had to add the plugin to the INSTALLED_APPS. But the order is here important.
我在使用djangocms时遇到了这个问题,并添加了一个插件(在我的例子中是djangocms-cascade)。当然,我必须将插件添加到INSTALLED_APPS中。但这里的秩序很重要。
To place 'cmsplugin_cascade' before 'cms' solved the issue.
将cmsplugin_cascade放在“cms”解决问题之前。
#9
2
install django-registration-redux==1.1 instead django-registration, if you using django 1.7
如果使用django 1.7,安装django-registration-redux==1.1,而不是django注册。
#10
-1
Your manage.py
is "wrong"; I don't know where you got it from, but that's not a 1.7 manage.py
- were you using some funky pre-release build or something?
你的管理。py是“错误的”;我不知道你从哪里得到的,但这不是一个1.7。py -你使用了一些时髦的预发布版本吗?
Reset your manage.py
to the conventional, as below, and things Should Just Work:
重设你的管理。py与常规,如下所示,一切都应该工作:
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "{{ project_name }}.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)