RemovedInDjango19Warning - 不在INSTALLED_APPS的应用程序中

时间:2016-07-13 10:54:05

标签: python django django-rest-framework

在Django中导入模块模块时出现以下错误。

/Users/markcollier/Documents/Adapt/Taboo/TabooAPI/env/lib/python2.7/site-packages/django/contrib/contenttypes/models.py:161: RemovedInDjango19Warning: Model class django.contrib.contenttypes.models.ContentType doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.

class ContentType(models.Model):

我已经四处寻找并尝试了所有类似问题的建议解决方案。

我认为这与我的settings.py文件的设置方式有关,但可能有误。非常感谢所有帮助。

settings.py

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

'django.contrib.sites',
'rest_framework',
'api.apps.ApiConfig',
]

REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': (
    'api.permissions.IsOwner',
)
}

MIDDLEWARE_CLASSES = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

apps.py

from __future__ import unicode_literals

from django.apps import AppConfig


class ApiConfig(AppConfig):
    name = 'api'

目录结构:

django_api
    api
        __init__.py
        apps.py

    migrations

    models.py
    permissions.py
    serializers.py
    signals.py
    temp.py
    urls.py
    views.py

    datasets

    django_site
        __init__.py
        settings.py
        urls.py
        wsgi.py

    db.sqlite3
    manage.py

1 个答案:

答案 0 :(得分:2)

根据您发布的错误消息,问题不在于您自己的应用,而在于django.contrib.django.contenttypes.models.ContentType - 并且Google搜索此确切的错误消息表明您不是第一个遇到此问题的人。

由于内容类型位于您已安装的应用中,因此问题来自内容类型,这些内容类型是在“官方”之前导入的。加载。因此,您需要知道的是找出导入contenttype的位置以及哪些导入过早发生 - 或者首先尝试将其放在您的设置INSTALLED_APPS中,如FeroxTL建议的那样,它可能(或不)解决问题。