我是django的新手。我尝试制作反馈应用,但我无法保存内容。它显示:
意外的论点“名字”
我的代码是
views.py
def index(request):
return render(request, 'index.html')
def positive(request):
if(request.method=="POST"):
confirm_message = " "
context = {'confirm_message': confirm_message}
name = request.POST['name']
suggest = request.POST['suggest']
improve = request.POST['improve']
posi = positive(name=name , suggest=suggest , improve=improve)
posi.save()
confirm_message = "Thanks for the message . We Will get right back to you."
context = {'confirm_message': confirm_message,}
return render(request,'positive.html',context)
else:
return render(request,'positive.html')
def negative(request):
if(request.method=="POST"):
confirm_message = " "
context = {'confirm_message': confirm_message}
name = request.POST['name']
upset = request.POST['upset']
change = request.POST['change']
negi = negative(name=name , upset=upset , change=change)
negi.save()
confirm_message = "Thanks for the message . We Will get right back to you."
context = {'confirm_message': confirm_message,}
return render(request,'negative.html',context)
else:
return render(request,'negative.html')
models.py
class positive(models.Model):
name = models.CharField(max_length=50,default=None)
suggest = models.CharField(max_length=100)
improve = models.CharField(max_length=150)
created_at = models.DateTimeField(default=datetime.now)
def __str__(self):
return u'Name : %s suggest: %s \nimprove: %s ' % (self.name,self.suggest,self.improve)
class negative(models.Model):
name = models.CharField(max_length=50,default=None)
upset = models.CharField(max_length=100)
change = models.CharField(max_length=100)
def __str__(self):
return u'Name : %s upset: %s \nchange: %s ' % (self.name,self.upset,self.change)