'EmailPostForm'对象没有属性'save'
我的观点
def post_share( request):
if request.method == 'POST':
form = EmailPostForm(request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect('/account/')
else:
form = EmailPostForm()
return render(request, 'accounts/home.html', {'form': form})
表格
class EmailPostForm(forms.Form):
name = forms.CharField(max_length=40)
lastname = forms.CharField(max_length=50)
comments = forms.CharField(required=False, widget=forms.Textarea)
specialization = forms.CharField()
他给我的'EmailPostForm'对象没有属性'保存'请帮助我
答案 0 :(得分:0)
当心您的'Forms.py'
class EmailPostForm(forms.ModelForm):
请记住,只有'Form'
继承自'forms.ModelForm'
才具有属性'save'
答案 1 :(得分:-1)
这行不通:
class EmailPostForm(forms.Form):
相反,请尝试这种方式:
class EmailPostForm(forms.Model.Form):
由于没有要保存的Model,如果要使用save,则必须使用Model.Form。