1.进行数据库迁移 python manage.py makemigrations python manage.py migrate
2.创建管理员
python manage.py createsuperuser 3.登陆网站 http://127.0.0.1:9000/admin/ 他这里应该是自带就有的吧 4.在数据库查看自己刚才登陆的用户名,密码 select * from user \G; 5.登陆页面 不知道为啥,我的登陆进去没有样式 6.在models里面写上:
from django.db import models # Create your models here. class Detail(models.Model): did = models.AutoField(primary_key=True) phone = models.CharField(max_length=20, blank=True, null=True) uid = models.IntegerField(blank=True, null=True) class Meta: managed = False db_table = 'detail' class User(models.Model): uid = models.AutoField(primary_key=True) username = models.CharField(max_length=30, unique=True) password = models.CharField(max_length=120) regtime = models.DateTimeField() sex = models.IntegerField(blank=True, null=True) class Meta: managed = False db_table = 'user' def __str__(self): return self.username + str(self.uid)7.在后台 python manage.py makemigrations python manage.py migrate 把刚才的2个表导入到数据库 No migrations to apply. 不知道为啥导入不了数据库 我重新建立了项目,重新导入了 跟java完全不一样 郁闷 8.注册模型类 在后台展示
9.在前台展示页面刷新 9.配置后台页面和添加数据的展示: 10.怎样显示3个字段
from django.contrib import admin from App.models import User, Detail # Register your models here. # 用户管理 class UserAdmin(admin.ModelAdmin): # 显示字段 list_display = ['pk', 'username', 'password'] # 注册模型类 在后台展示 admin.site.register(User, UserAdmin) admin.site.register(Detail)