Django的内置的用户模型实现 [英] Django built-in User Model implementation

查看:142
本文介绍了Django的内置的用户模型实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用内置的Django在我的应用程序提供用户模式,但我不知道如何实现它(即,什么是我的models.py文件实际上是什么样子的?),我开始关闭通过构建一个简单的登录表单与Django的身份验证系统。

I'm trying to use the built in User model provided by Django in my app, but I'm not sure how to implement it (i.e., what does my models.py file actually look like?) I'm starting off by building a simple login form with the Django auth system.

我看到那里导入用户,但从来没有任何定义网络上的多个例子。像这样

I'm seeing multiple examples on the web where they import User but never define anything. Like so

from django.db import models
from django.contrib.auth.models import User

#nothing similar to defining User (i.e. 'class User: #fields')

什么我假设是通过导入用户,你没有定义任何东西,因为它已经被定义,但是当我去跑蟒蛇manage.py SQL'名'什么都不执行。

What I'm assuming is by importing User, you don't have to define anything, since it's already been defined, but when I go to run "python manage.py sql 'name'" nothing is executed.

推荐答案

您不需要为用户模型文件,因为Django的已经提供的。你只需要确保 django.contrib.user 在INSTALLED_APPS。

You don't need a models file for the user, because Django already supplies one. You just need to ensure that django.contrib.user is in INSTALLED_APPS.

您将需要导入用户到另一个模型文件的唯一原因是,如果你想从你自己的车型之一添加一个ForeignKey的到用户模式。在所有的可能性,你的的想做的事情,最终,但你不必只是为了获取用户的模型创建的。

The only reason you would need to import User into another models file is if you wanted to add a ForeignKey from one of your own models to the User model. In all likelihood, you do want to do that eventually; but you don't need to just in order to get the user models created.

这篇关于Django的内置的用户模型实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆