I'm currently making a django website, and I'm confused between using Django-Forms and the traditional hand coded HTML forms. HTML forms works in my favor in many ways, but I've also tried django forms and they definitely have their advantages. Any help on this will be appreciated.
If you're creating a form in which the data goes into a database table, Django's form is easier as well. The data is easily transferrable from form to database table with Django forms. If you creating any type of complex form that creates complex styling, it's easier to go with plain HTML forms.
The similarities are that they both generate sets of form inputs using widgets, and both validate data sent by the browser. The differences are that ModelForm gets its field definition from a specified model class, and also has methods that deal with saving of the underlying model to the database. Save this answer.
It's recommended to use the forms api provided by Django since it allows you to reuse, validate, and customize your forms. As to whether or not it is a good practice that depends completely on you but if you are trying to scale an application I would recommend use the forms.
In this case, our form has four fields: subject , message , sender and cc_myself . CharField , EmailField and BooleanField are just three of the available field types; a full list can be found in Form fields.
In my opinion Django forms is great when you have a simple application that gets data from a user in a format that is close to the way that you want to store it in the database. In this scenario you can simply write the model and use model forms to generate the correct HTML for you form.
You can also use forms to get data from the user that doesn't correspond to a model by using a normal form and defining its properties.
With Django forms you also get some validation for free, you can make fields optional or required and you can create drop down options.
Where it gets a little more difficult is when you have certain fields that you want to display in a custom way. You can still use Django forms, but you need to work a little harder.
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