在我第一次提交表單並刷新表單後,它會重新提交併且我不希望這樣。django表單在刷新時重新提交
這裏是我的模板形式:
<form action = "" method = "POST"> {% csrf_token %}
{{ form.as_p }}
<input type = "submit" value = "Shout!"/>
</form>
我怎樣才能解決這個問題?
這是我的觀點:
def index(request):
shouts = Shout.objects.all()
if request.method == "POST":
form = GuestBookForm(request.POST)
if form.is_valid():
cd = form.cleaned_data
shout = Shout(author = cd['author'], message = cd['message'])
shout.save()
form = GuestBookForm()
else:
form = GuestBookForm()
return render_to_response('guestbook/index.html', {'shouts' : shouts,
'form' : form },
context_instance = RequestContext(request))
解釋你的看法 – vad 2011-04-28 18:58:14