1
用戶提交表單並且未填寫必填字段時,我試圖丟棄'所需字段'消息。
正在發生的事情是,即使在提交表單之前,仍然顯示錯誤。提交後不應該進行驗證?提交表單之前「字段爲必填信息」
我有以下形式:
class LookforPlace(forms.Form):
name = forms.CharField(required=True,max_length=100,label='Name',error_messages = {'required': "This field is required..."})
city = forms.CharField(required=False,label='City')
email = forms.EmailField()
我有以下看法:
def newreview(request):
if request.method == 'GET': # If the form has been submitted...
form = LookforPlace(request.GET) # A form bound to the GET data
if form.is_valid(): # All validation rules pass
return HttpResponseRedirect('/newreview/valid') # Redirect after GET
else:
form = LookforPlace() # An unbound form
return render_to_response('newreview.html', {
'form': form,
})
和我有下面的HTML代碼:
<form action="/newreview/" method="get">
{% for field in form %}
<div class="fieldWrapper">
{{ field.errors }}
{{ field.label_tag }}: {{ field }}
</div>
{% endfor %}
<input type="submit" value="Submit" />
</form>
非常感謝。我不知道。儘管如此,我想用POST是不一樣的。 – Nobita