Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 605
doniyor Avatar asked Sep 18 '13 16:09

doniyor


People also ask

Why do we use forms in Django?

Django provides a Form class which is used to create HTML forms. It describes a form and how it works and appears. It is similar to the ModelForm class that creates a form by using the Model, but it does not require the Model.

What are the advantages of Django forms over 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. Save this answer.

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.

Why use Django crispy forms?

Django-crispy-forms is an application that helps to manage Django forms. It allows adjusting forms' properties (such as method, send button or CSS classes) on the backend without having to re-write them in the template.


2 Answers

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.

like image 154
Private Avatar answered Sep 28 '22 04:09

Private


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

like image 33
Srinivas Reddy Thatiparthy Avatar answered Sep 28 '22 04:09

Srinivas Reddy Thatiparthy