-1π
β
def register(req):
if req.method == "POST":
uf = UserForm(req.POST)
if uf.is_valid():
....
return HttpResponse('ok')
# If control flow is reach here, nothing is returned.
else:
uf = UserForm()
return render_to_response('register.html',{'uf':uf})
If an invalid POST
request is come, the view will return nothing. (implicitly None)
Try following:
def register(req):
if req.method == "POST":
uf = UserForm(req.POST)
if uf.is_valid():
....
return HttpResponse('ok')
uf = UserForm()
return render_to_response('register.html',{'uf':uf})
π€falsetru
2π
You need to decrease the indent of the last line. That should be caught both by the case where it is not a POST, and when it is a POST but the form is invalid.
π€Daniel Roseman
- [Answer]-How to use foreignKey?
- [Answer]-Django β retrieve form data
- [Answer]-Django 1.6 how to first filter according to another model, then order the model?
- [Answer]-Validating a formset
Source:stackexchange.com