model(增删改查)
在数据库中创建表:
from datetime import datetime
from django.db import models
# Create your models here.
class User(models.Model):
# 属性
# id = models.AutoField()
# id = models.IntegerField(primary_key=True)
username = models.CharField(max_length=15)
password = models.CharField(max_length=12)
age = models.IntegerField()
gender = models.BooleanField(default=False)
phone = models.CharField(max_length=11)
# join_date = models.DateTimeField(default=datetime.now)
join_date = models.DateTimeField(auto_now=True)
# 用于修改表的名字
class Meta:
db_table = 'user'
#返回表中的值
def __str__(self):
return self.username
用户注册:
# 用户注册
def register(request):
if request.method == 'POST':
# 获取表单数据
username = request.POST.get('username')
password = request.POST.get('password')
cpassword = request.POST.get('cpassword')
age = request.POST.get('age')
gender = request.POST.get('gender')
phone = request.POST.get('phone')
print(username, password, age, gender, ph