1
我試圖建立一個聯繫表單,並暫時試圖讓它顯示提交按鈕被擊中(同一頁)時提交的字段。當我點擊提交,它會重新加載與聯繫表格顯示。所以,這裏是我的觀點:django:簡單的聯繫表單不工作
from website.forms import ContactForm
def contact(request):
Success = False
email = ""
title = ""
text = ""
if request.method == "POST":
contact_form = ContactForm(request.POST)
if contact_form.is_valid():
Success = True
email = contact_form.cleaned_data['email']
title = contact_form.cleaned_data['title']
text = contact_form.cleaned_data['text']
else:
contact_form = ContactForm()
ctx = {'contact_form':contact_form, 'email':email, 'title':title, 'text':text, 'success':success}
return render_to_response('website/contact.html', ctx, context_instance=RequestContext(request))
這裏的forms.py:
from django import forms
class ContactForm(forms.Form):
email = forms.EmailField()
title = forms.CharField()
text = forms.CharField(widget=forms.Textarea)
而這裏的模板:
{% if success %}
<p>{{ email }}</p>
<p>{{ title }}</p>
<p>{{ text }}</p>
{% else %}
<form action"." method="POST">
{{ contact_form.as_p }}
<input type="submit" value="Send">
<input type="reset" value="Reset">
</form>
{% endif %}
這似乎很簡單,但我究竟做錯了什麼?
太好了,謝謝就是這樣。 – babbaggeii 2013-03-28 09:06:30
如果是這樣,請接受我的安裝程序:) – daveoncode 2013-03-28 09:07:53
完成後,我只是等到它讓我接受它。 – babbaggeii 2013-03-28 09:12:41