I've got a Django form with a bunch of fields that I'm rendering in the template. I've also got some straight HTML input elements which I want to validate in the view by accessing the request.POST
vars. If those don't validate, I want to inject an error into the Django form so I can display it on the page. Is there a way to do that?
You can also use quite elegant add_error() method. Works for Django >= 1.7.
If you set field
as None
form will treat the error as "non_field" one. So:
form.add_error(None, "I'm non-field error")
works like a charm.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With