Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django forms vs traditional forms

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.

like image 890
Varun Rathore Avatar asked Aug 03 '12 17:08

Varun Rathore


People also ask

Is it better to use Django forms or HTML forms?

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.

What is the difference between forms and model forms in Django?

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.

Is Django form necessary?

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.

How many types of Django forms are there?

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.


1 Answers

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.

like image 121
Dirk Avatar answered Oct 23 '22 08:10

Dirk