我试图在我的模型中保存Django上的表单数据,但是当我提交表单并看到Django管理页面时,有任何更改。
forms.py:
Form
这是我的view.py
class PublisherForm(ModelForm):
class Meta:
model = Publisher
fields = ['name','address','city','state_province','country','website']
form = PublisherForm #Creating a form to add a Publisher
和我的models.py:
def add_publisher(request):
if request.method == 'POST':
form = PublisherForm(request.POST)
if form.is_valid():
new_publisher=form.save()
return HttpResponseRedirect('/thanks/')
else:
print form.errors
else:
form = PublisherForm()
return render_to_response('add_publisher.html', {'form':form})
任何人都可以帮助我?
答案 0 :(得分:0)
offtopic ,但这是使用表单的一种简单方法。
def add_publisher(request):
form = PublisherForm(request.POST or None)
if request.method == 'POST' and form.is_valid():
new_publisher = form.save()
return HttpResponseRedirect('/thanks/')
return render_to_response('add_publisher.html', {'form':form})