[Fixed]-Django – guidance needed

1👍

You could use either option.

Option #1: In the post method (if using Class-based-views, otherwise check for “post” as the request type), just instantiate the form with MessageForm(request.POST), and then check the form’s is_valid() method. If the form is valid, save the Message object and redirect back to the same view using HttpResponseRedirect within the if form.is_valid(): code block.

If you’re checking for the related Messages objects in your template, the newly created message should be there.

Option #2: Very similar to Option #1, except if the form is not valid, re-render the same template that is used for the product_view with the non-valid form instance included in the template context.

Leave a comment