Let’s say I’m making a blogging web application using Python and the web framework, Django. I want users to be able to publish “Posts” on my blogging website.
When they enter that “Post” into some sort of input form that I have on my website, I want to check the “Post” before I save it to my database.
This is a common scenario for many Django developers. How do we validate form data before we save it to a database?
There’s two common ways to do it: Either validate the Model or validate the Form.
Django has Forms and Models. Very basically, Forms are where users input data on a web application, and Models and where I actually save my information in my program.
Let’s look first at how to validate the Model: