Cannot get is_valid() to go back to template with bound form

In the Django docs, it says

“We call the form’s is_valid() method; if it’s not True, we go back to
the template with the form. This time the form is no longer empty
(unbound) so the HTML form will be populated with the data previously
submitted, where it can be edited and corrected as required.”

I am trying to get this behaviour to work.

In views.py:

def test(request):
    if request.method == 'POST':
        form = TestForm(request.POST)

        if form.is_valid():
            return redirect('auctions/test.html')

    else:
        form = TestForm()
        print(form)
        return render(request, 'auctions/test.html', {'form': form})

In forms.py:

class TestForm(forms.Form):
    testnumber = forms.DecimalField(max_digits=1)

In test.html:

<form action="{% url 'auctions:test' %}" method="post">
    {% csrf_token %}
    {{ form }}
    <input type="submit" value="Submit">
</form>

Now, when I submit the form with a number that is more than 1 digit, is_valid() evaluates to False. When that happens, the docs says the template should be rendered with the bound form and the error. Instead, nothing happens, and I get ValueError: The view auctions.views.test didn't return an HttpResponse object. It returned None instead.

Go to Source
Author: Ryan Eom