2019.03.21 admin

1.新建文件创建一个应用类 stu

Python manage.py startapp stu

2,创建应用类 记得在setting中的installed_apps中添加应用

student/models.py中创建Stu模型类   写下自己需要的字段名

    # -*- coding: utf-8 -*-
  from __future__ import unicode_literals
   
  from django.db import models
   
  # Create your models here.
   
  class Stu(models.Model):
      sname = models.CharField(max_length=20,unique=True)
      spwd = models.CharField(max_length=20,unique=True)

创建数据库表

1.创建当前应用的迁移文件

python manage.py makemigrations stu

2.生成数据库表

python manage.py migrate

编辑admin.py(student/admin.py)

    # -*- coding: utf-8 -*-
  from __future__ import unicode_literals
   
  from django.contrib import admin
  from models import *
   
  # Register your models here.
  admin.site.register(Stu)

创建账户密码



  python manage.py createsuperuser

重启服务器

然后就可以登录后台admin站点 管理数据库了

 

原文地址:https://www.cnblogs.com/Py-king/p/10571962.html