[Fixed]-Form.is_valid is not validating

1👍

You shouldn’t return a response from get_context_data(). Instead, do that in the post() method like this:

class BoxesView(ListView):
    template_name = 'polls.html'

    def post(self, request, *args, **kwargs):
        form = UserRegistrationForm(request.POST)

        if form.is_valid(): 
            username = form.cleaned_data['username']
            password = form.cleaned_data['password']
            user = User.objects.create_user(username, password=password)
            return redirect('/')
        else:
            return self.get(request, *args, **kwargs)

    def get_context_data(self):
        context = super(BoxesView, self).get_context_data()
        context['form'] = UserRegistrationForm()
        return context

0👍

Looks like your Form expects to have confirm_password submitted, but that’s not part of your html form.

Leave a comment