Django 之Auth模块

Python65

Auth 模块是Django中自带的用户认证模块。

一个网站系统需要实现用户注册、用户登录、用户认证、注销、修改密码等功能,Django中内置了强大的认证系统-auth,默认使用 auth_user表来存储用户的数据。

同时Django有一个后台管理系统(127.0.0.1:8000/admin),使用的用户名和密码也是这张数据表中的数据。

默认后台管理没有用户名和密码,我们需要创建一个,只有超级管理员才能登录到这个页面,所以现在让我们创建一个这样的超级用户。

[En]

There is no user name and password for the default background management, we need to create one, and only a super administrator can log on to this page, so let's create such a super user now.

在一个新的项目中,先设计项目的数据库,表关系,Django 系统内置的认证系统(auth_user表)很好用,但是表字段都是固定的几个,无法进行对它扩展。

例如,如果默认字段不足以让我们使用,我们可以扩展它,存储用户的手机号、时间等字段,并设置表和表之间的关系。

[En]

For example, if the default field is not enough for us to use, we can extend it, store the user's mobile number, time, and other fields, and set the relationship between the table and the table.

现在就来设计扩展一下这个表,需要两步

1配置settings

在 settings.py 配置文件中增加一句话,告诉Django 使用新定义的 UserInfo 表来做用户认证的表。

```

settings.py

输入验证码查看隐藏内容

扫描二维码关注本站微信公众号 Johngo学长
或者在微信里搜索 Johngo学长
回复 svip 获取验证码
wechat Johngo学长