你为什么要扩展用户?请澄清。
如果您要添加有关用户的更多信息,则无需滚动您自己的用户和身份验证系统。Django 的版本非常可靠。用户管理位于 django.contrib.auth。
如果需要自定义与用户一起存储的信息,首先定义一个模型如
class Profile(models.Model):
...
user = models.ForeignKey("django.contrib.auth.models.User", unique=True)
然后设置
AUTH_PROFILE_MODULE = "appname.profile"
在你的 settings.py
设置它的好处是允许您在视图中使用这样的代码:
def my_view(request):
profile = request.user.get_profile()
etc...
如果您尝试为用户提供更多身份验证方式,则可以添加身份验证后端。扩展或重新实现 django.contrib.auth.backends.ModelBackend 并在 settings.py 中将其设置为您的 AUTHENTICATION_BACKENDS。
If you want to make use of a different permissions or groups concept than is provided by django, there's nothing that will stop you. Django makes use of those two concepts only in django.contrib.admin (That I know of), and you are free to use some other concept for those topics as you see fit.