ContentType没有声明显式的app_label [英] ContentType doesn't declare an explicit app_label
问题描述
我正在使用Apache和mod_wsgi将Django 1.10项目部署到Ubuntu服务器上.我遇到以下无法解决的500错误:
I am deploying a Django 1.10 project onto an Ubuntu server with Apache and mod_wsgi. I am getting the following 500 error which I can't solve:
RuntimeError:模型类 django.contrib.contenttypes.models.ContentType没有声明 明确的app_label,并且不在INSTALLED_APPS的应用程序中.
RuntimeError: Model class django.contrib.contenttypes.models.ContentType doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
settings.py中的installed_apps:
installed_apps in settings.py:
INSTALLED_APPS = [
'django.contrib.sites',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'dashboard',
]
wsgi.py:
sys.path.append('/home/x_dashboard/x_dashboard/')
activate_this = os.path.expanduser("/home/x_dashboard/.venv/bin/activate_this.py")
execfile(activate_this, dict(__file__=activate_this))
os.environ['PYTHON_EGG_CACHE'] = '/home/x_dashboard/x_dashboard/.python-egg'
os.environ['DJANGO_SETTINGS_MODULE'] = 'x_dashboard.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
Apache配置:
<VirtualHost *:80>
#ServerName example.com
#ServerAlias www.example.com
#ServerAdmin username@example.com
DocumentRoot /home/x_dashboard/x_dashboard/
#ErrorLog /var/www/html/example.com/logs/error.log
#CustomLog /var/www/html/example.com/logs/access.log combined
WSGIScriptAlias / /home/x_dashboard/x_dashboard/x_dashboard/wsgi_local.py
#Alias /robots.txt /var/www/html/example.com/public_html/robots.txt
#Alias /favicon.ico /var/www/html/example.com/public_html/favicon.ico
#Alias /images /var/www/html/example.com/public_html/images
Alias /static /var/www/x_dashboard/static
<Directory /home/x_dashboard/x_dashboard/x_dashboard/>
<Files wsgi.py>
Order deny,allow
Allow from all
Require all granted
</Files>
</Directory>
</VirtualHost>
Django文档说,不属于install_apps中定义的应用程序的模型需要app_label.但是,"django.contrib.contenttypes" 是在installed_apps中定义的.
The Django documentation says that an app_label is required for models which do not belong to an app defined in installed_apps. However, 'django.contrib.contenttypes' is defined in installed_apps.
任何帮助表示赞赏.
推荐答案
对于其他正在解决此错误的人:我通过将'django.contrib.contenttypes'移动到settings.py中我install_apps列表的顶部来解决了该问题.
For anyone else struggling with this bug: I solved it by moving 'django.contrib.contenttypes', to the top of my installed_apps list in settings.py.
我也搬了
import django
django.setup()
到install_apps之后. 该线程很有帮助.
to after installed_apps. This thread was helpful.
这篇关于ContentType没有声明显式的app_label的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!