1.Django自带的用户表
create table auth_user ( id int auto_increment primary key, password varchar(128) not null, last_login datetime(6) null, is_superuser tinyint(1) not null, username varchar(150) not null, first_name varchar(30) not null, last_name varchar(30) not null, email varchar(254) not null, is_staff tinyint(1) not null, is_active tinyint(1) not null, date_joined datetime(6) not null, constraint username unique (username) );
2.创建自定义表models.User
from django.contrib.auth.models import AbstractUser class User(AbstractUser): """用户模型类""" mobile = models.CharField(max_length=11, verbose_name='手机号') class Meta: db_table = 'tb_users' verbose_name = "用户信息表" verbose_name_plural = verbose_name def __str__(self): return self.username
3.注册自定义表 admin.UserAdmin
from django.contrib import admin from .models import User class Useradmin(admin.ModelAdmin): list_display = ['username', 'password', 'mobile'] # Register your models here. admin.site.register(User, Useradmin) # 用UserAdmin去注册User
4.settings添加user表
#自定义用户表 AUTH_USER_MODEL = 'app名字.User'
5.登录后台查看