1👍
You are currently creating a new form for POST requests when the form is invalid. That means you don’t see the form errors.
Instead, you can move the MyregistrationForm()
into the else
statement, so that it only runs for GET requests. To do this you need to rearrange the view slightly. I’ve switched from render_to_response
to render
to make this easier.
def register(request):
if request.method == 'POST':
form = MyregistrationForm(request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect('congratulations')
else:
form = MyregistrationForm()
return render(request, 'page/register.html', {'form': form})
With your new view, you should see the form errors in the template. This will give you a clue why the form is invalid.
Source:stackexchange.com