Django RuntimeError:模型类django.contrib.contenttypes.models.ContentType错误

时间:2018-10-18 19:27:07

标签: python django

我正在使用Django 2。 我正在获取此错误代码,我在网上查找了所有内容,但没有找到任何解决办法来修复为何不断向我提供此错误代码的问题。

Traceback (most recent call last):
  File "/home/matthew/anaconda3/lib/python3.6/site-packages/django/utils/autoreload.py", line 225, in wrapper
    fn(*args, **kwargs)
  File "/home/matthew/anaconda3/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 117, in inner_run
    self.check(display_num_errors=True)
  File "/home/matthew/anaconda3/lib/python3.6/site-packages/django/core/management/base.py", line 379, in check
    include_deployment_checks=include_deployment_checks,
  File "/home/matthew/anaconda3/lib/python3.6/site-packages/django/core/management/base.py", line 366, in _run_checks
    return checks.run_checks(**kwargs)
  File "/home/matthew/anaconda3/lib/python3.6/site-packages/django/core/checks/registry.py", line 71, in run_checks
    new_errors = check(app_configs=app_configs)
  File "/home/matthew/anaconda3/lib/python3.6/site-packages/django/core/checks/urls.py", line 40, in check_url_namespaces_unique
    all_namespaces = _load_all_namespaces(resolver)
  File "/home/matthew/anaconda3/lib/python3.6/site-packages/django/core/checks/urls.py", line 57, in _load_all_namespaces
    url_patterns = getattr(resolver, 'url_patterns', [])
  File "/home/matthew/anaconda3/lib/python3.6/site-packages/django/utils/functional.py", line 37, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/home/matthew/anaconda3/lib/python3.6/site-packages/django/urls/resolvers.py", line 533, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/home/matthew/anaconda3/lib/python3.6/site-packages/django/utils/functional.py", line 37, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/home/matthew/anaconda3/lib/python3.6/site-packages/django/urls/resolvers.py", line 526, in urlconf_module
    return import_module(self.urlconf_name)
  File "/home/matthew/anaconda3/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/matthew/mykoio/mykoio/urls.py", line 21, in <module>
    path('website/', include('website.urls')),
  File "/home/matthew/anaconda3/lib/python3.6/site-packages/django/urls/conf.py", line 34, in include
    urlconf_module = import_module(urlconf_module)
  File "/home/matthew/anaconda3/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/matthew/mykoio/website/urls.py", line 3, in <module>
    from . import views
  File "/home/matthew/mykoio/website/views.py", line 6, in <module>
    from django.contrib.auth.forms import UserCreationForm
  File "/home/matthew/anaconda3/lib/python3.6/site-packages/django/contrib/auth/forms.py", line 10, in <module>
    from django.contrib.auth.models import User
  File "/home/matthew/anaconda3/lib/python3.6/site-packages/django/contrib/auth/models.py", line 3, in <module>
    from django.contrib.contenttypes.models import ContentType
  File "/home/matthew/anaconda3/lib/python3.6/site-packages/django/contrib/contenttypes/models.py", line 134, in <module>
    class ContentType(models.Model):
  File "/home/matthew/anaconda3/lib/python3.6/site-packages/django/db/models/base.py", line 95, in __new__
    "INSTALLED_APPS." % (module, name)
RuntimeError: Model class django.contrib.contenttypes.models.ContentType doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.

我安装的应用程序是:

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

出于某种原因,我得到了人们推荐的所有应用程序,无论如何,我都会尝试它们,并且得到相同的错误代码。我现在能想到的是,进一步的Django代码还是有问题。

1 个答案:

答案 0 :(得分:0)

INSTALLED_APPS = ['django.contrib.admin','django.contrib.auth','django.contrib.auth.views','django.contrib.contenttypes','django.contrib.sessions','django .contrib.messages”,“ django.contrib.staticfiles”,“网站”,]

这应该有效。