form.valid不起作用,当我使用html表单填写数据应存储在数据库中的表单以及如何上传图像,如何在html页面中定义表单时,我的代码中是否有任何错误,如下给出了我的models.py,views.py,forms.py,我搜索了很多论坛,但无法获得答案
class Deal(models.Model):
Deal_Category = models.CharField(max_length=30, choices=(('F','Fashion'),
('T', 'Travel') ))
Deal_Title = models.CharField(max_length=30,blank=True)
Deal_Redemption = models.CharField(max_length=50,blank=True)
Deal_Start = models.DateField()
Deal_End =models.DateField()
Deal_Details = models.CharField(max_length=50,blank =True)
Deal_Location= models.CharField(max_length=50,blank =True)
Deal_Terms = models.CharField(max_length=50,blank =True)
#Images = models.ImageField(upload_to='static/image',blank=True)
class DealForm(forms.ModelForm):
class Meta():
model= Deal
fields=('Deal_Category','Deal_Title','Deal_Redemption','Deal_Start','Deal_End','Deal_Details',
'Deal_Location','Deal_Terms')
def deal_form(request):
print("Deal")
if request.method == 'POST':
print("user")
form = DealForm(data=request.POST )
print("Deal1")
if form.is_valid():
print("Deal2")
form.save(commit=True)
print("Deal4")
return render(request, 'advertizer/adver_create_coupon.html')