doniyor
doniyor

Reputation: 37904

why should I use django forms

I am starting a new project again in django and so far i have never used django forms. Now i am wondering why i should use it and what it would save me. I still feel, by using django forms, i am not free in terms of html styling with frontend frameworks like bootstrap.

why should I use django forms? 

can you guys please guide me a bit?

Upvotes: 13

Views: 5343

Answers (3)

Suban Chaudhary
Suban Chaudhary

Reputation: 21

Because it is a good practice and for all the security purposes.

Upvotes: 1

From Django docs,

using the form library takes care of a number of common form-related tasks. Using it, you can:

  1. Display an HTML form with automatically generated form widgets.

  2. Check submitted data against a set of validation rules.

  3. Redisplay a form in the case of validation errors.

  4. Convert submitted form data to the relevant Python data types.

For more info, please read that documentation

Upvotes: 8

Private
Private

Reputation: 2694

i am not free in terms of html styling with frontend frameworks like bootstrap.

There is a very easy solution to this: use django-crispy-forms and regain all control of what your form looks like frontend. There is good documentation which includes parts on how to make your forms use bootstrap.

i am wondering why i should use it and what it would save me.

The question really is "do you have any good reason not to use django.forms?" Because really, if you are not using django.forms you throw away a lot of django's built-in security measures. Even within django itself (for instance the admin site) forms are used heavily. Thus I doubt your previous project really did not use django forms.

If you are building an API you might want to look at how tastypie or django rest framework go about validation data.

Upvotes: 17

Related Questions