Varun Rathore
Varun Rathore

Reputation: 7898

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.

Upvotes: 8

Views: 4185

Answers (5)

wobbily_col
wobbily_col

Reputation: 11911

The primary purpose of Django forms is to validate data.

You can use them with data not submitted through an HTML POST. Rendering them, as HTML is something else that they do, but it isn't their main purpose.

Upvotes: 1

Dirk
Dirk

Reputation: 1234

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.

Upvotes: 6

Marcin
Marcin

Reputation: 49856

Django forms are a way of generating forms on the page, and managing them. You can hand code the form on the page, and as long as you use field names compatible with those that your form class expects, you can use the form class to interact with the data sent in your response.

Ultimately, django forms will definitely make your life easier.

Upvotes: 2

zaphod
zaphod

Reputation: 2095

Think of Django forms as DRY of HTML forms.
With Django forms, the standard forms HTML is auto-generated for you and you have to write code for only where you want to customize the form.
Django forms also handle form validation for you, and you can override with self-written code only when you want some special case validation.

Upvotes: 3

Calvin Jia
Calvin Jia

Reputation: 856

If you are using django to develop your website, I think it is best to only use django-forms since they have built in validation and can easily be linked with your models. You also will have consistent formatting and don't need to type out the html every time.

You might also want to check out crispy-forms for more customization.

Upvotes: 3

Related Questions