[Fixed]-Django POST form validation to an another page

1👍

Base on your description and views.py, you stay on step 2 that’s why:

  1. User is on page ‘/step_1/’
  2. He submit form
  3. Because action param in form is point to ‘/step_2/’, it’s going to that url
  4. In view request.method == ‘POST’ is True, but form is not valid.
  5. You are rendering template from ‘/step_1’, but not redirecting User.

So here is sample fix:

def step2(request):
    print(request.POST)
    if request.method == 'POST':
        form = SearchShowForm(request.POST)
        if form.is_valid():
            print(form.cleaned_data)
            return render(request, 'tvshows_manager/step_2.html', {'data': form.cleaned_data})
        else:
            return HttpResponseRedirect('/step_1/')
    else:
        return HttpResponseRedirect('/step_1/')

Leave a comment