1、建模型
class Student(models.Model):
stuName=models.CharField(max_length=20)
2、生成迁移文件
python manage.py makemigrations
3、执行迁移(生成数据库表)
python manage.py migrate
4、视图
from django.shortcuts import render,HttpResponse
# Create your views here.
from app01.models import Student
def index(req):
Student.objects.create(stuName='bbb')
return HttpResponse("ok")
def index2(req):
return render(req,"index.html")
def index3(req):
stus=Student.objects.all()
return render(req,"index.html",locals())
本内容试读结束,登录后可阅读更多
下载后可阅读完整内容,剩余4页未读,立即下载