from django.db import models
# Create your models here.
class UserInfo(models.Model):
#CharField是一个字段,相当于字符串
username=models.CharField(max_length=64)
sex=models.CharField(max_length=64)
email=models.CharField(max_length=64)
================================================
在控制台输入:
python manage.py makemigrations
python manage.py migrate
===============================================
def userInfo(req):
# req.POST={'username',star,'sex':mail,'email':123@.com}
if req.method=='POST':
u=req.POST.get('username',None)
s=req.POST.get('sex',None)
e=req.POST.get('email',None)
# user={'username':u,'sex':s,'email':e}
# user_list.append(user)
#将数据存入到数据库
models.UserInfo.objects.create(
username=u,
sex=s,
email=e,
)
#将数据从数据库中取出来呈现到页面上
user_list=models.UserInfo.objects.all()
return render(req, 'index.html',{'user_list':user_list})