[Django]-"Field is required message" before submitting form

3👍

A GET is issued when you browse to a page normally, not just when you submit a form with that method – if you want to use the same view to display an initial form and handle submission via GET, you should check for a value from the form having been submitted.

One option is to give the submit button a name…

<input type="submit" name="submit" value="Submit">

…and check for that name having been submitted as a parameter (this is also a good way to handle forms with multiple submit buttons, as only the button which was clicked will count as a successful control and have its name submitted as a parameter in the request):

if 'submit' in request.GET:
    # ...

Leave a comment