我想要做的是,如果用户在 18 岁以上,那么请他填写表格……如果低于 18 岁,那么请他填写不同的表格并将表格保存到数据库中视图.pyfrom django.shortcuts import renderfrom app1.form import UserFormfrom django.http import HttpResponse# Create your views here.def home(request): return render(request,"home.html")def formpage(request): form=UserForm() if(request.method=='POST'): form=UserForm(request.POST) if(form.is_valid()): form.save() return home(request) return render(request,'formpage.html',{'form':form})模型.pyfrom django.db import models# Create your models here.gen_opts= [('male','Male'),('female', 'Female'),]class MyUser(models.Model): name=models.CharField(max_length=40) gender = models.CharField(max_length=6, choices=gen_opts) age= models.PositiveIntegerField() ph.num=models.PositiveIntegerField() check_box = models.BooleanField() def __str__(self): return self.name表格.pyfrom app1.models import MyUserfrom django import formsclass UserForm(forms.ModelForm): class Meta(): model=MyUser fields='__all__'
添加回答
举报
0/150
提交
取消