Django 1.9 和 django.contrib.auth
Django 1.9 and django.contrib.auth
我在 INSTALLED_APPS
中没有 django.contrib.auth
,我不想这样做,因为我使用的是自定义用户模型,我不需要 none 的内置 User
、Group
和 Permission
模型。
我希望这在 Django 1.9 中是可能的,正如 https://docs.djangoproject.com/en/1.9/releases/1.9/ 中 django.contrib.auth
部分下的文档所述:
AbstractBaseUser
and BaseUserManager
were moved to a new django.contrib.auth.base_user
module so that they can be imported without including django.contrib.auth
in INSTALLED_APPS
(doing so raised a deprecation warning in older versions and is no longer supported in Django 1.9).
但是,到目前为止,我无法在不引发错误的情况下从 django.contrib.auth
导入任何内容。不能导入任何中间件或表单。我必须将 django.contrib.auth
添加到 INSTALLED_APPS
或不使用该模块中的任何内容。
每当间接导入 django.contrib.auth
中的模型时,我都会收到经典错误:whatever_model_was_indirectly_imported
未声明显式 app_label
且不在 [= 中的应用程序中13=].
编辑: 包括追溯的最后一部分:
...
File "/usr/lib/python2.7/site-packages/django/contrib/auth/middleware.py", line 3, in <module>
from django.contrib.auth.backends import RemoteUserBackend
File "/usr/lib/python2.7/site-packages/django/contrib/auth/backends.py", line 4, in <module>
from django.contrib.auth.models import Permission
File "/usr/lib/python2.7/site-packages/django/contrib/auth/models.py", line 38, in <module>
class Permission(models.Model):
File "/usr/lib/python2.7/site-packages/django/db/models/base.py", line 102, in __new__
"INSTALLED_APPS." % (module, name)
RuntimeError: Model class django.contrib.auth.models.Permission doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
有什么解决方法吗?
目前看来唯一的解决方法是在 INSTALLED_APPS
中包含 django.contrib.auth
并忽略数据库中的三个表。
我在 INSTALLED_APPS
中没有 django.contrib.auth
,我不想这样做,因为我使用的是自定义用户模型,我不需要 none 的内置 User
、Group
和 Permission
模型。
我希望这在 Django 1.9 中是可能的,正如 https://docs.djangoproject.com/en/1.9/releases/1.9/ 中 django.contrib.auth
部分下的文档所述:
AbstractBaseUser
andBaseUserManager
were moved to a newdjango.contrib.auth.base_user
module so that they can be imported without includingdjango.contrib.auth
inINSTALLED_APPS
(doing so raised a deprecation warning in older versions and is no longer supported in Django 1.9).
但是,到目前为止,我无法在不引发错误的情况下从 django.contrib.auth
导入任何内容。不能导入任何中间件或表单。我必须将 django.contrib.auth
添加到 INSTALLED_APPS
或不使用该模块中的任何内容。
每当间接导入 django.contrib.auth
中的模型时,我都会收到经典错误:whatever_model_was_indirectly_imported
未声明显式 app_label
且不在 [= 中的应用程序中13=].
编辑: 包括追溯的最后一部分:
...
File "/usr/lib/python2.7/site-packages/django/contrib/auth/middleware.py", line 3, in <module>
from django.contrib.auth.backends import RemoteUserBackend
File "/usr/lib/python2.7/site-packages/django/contrib/auth/backends.py", line 4, in <module>
from django.contrib.auth.models import Permission
File "/usr/lib/python2.7/site-packages/django/contrib/auth/models.py", line 38, in <module>
class Permission(models.Model):
File "/usr/lib/python2.7/site-packages/django/db/models/base.py", line 102, in __new__
"INSTALLED_APPS." % (module, name)
RuntimeError: Model class django.contrib.auth.models.Permission doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
有什么解决方法吗?
目前看来唯一的解决方法是在 INSTALLED_APPS
中包含 django.contrib.auth
并忽略数据库中的三个表。