[go: up one dir, main page]

0% found this document useful (0 votes)
17 views10 pages

Widgets in DjangoForm

Uploaded by

Aniket Kadam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views10 pages

Widgets in DjangoForm

Uploaded by

Aniket Kadam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

by Kunal Sir

Some important parameters

 label --> to change the default label default label is field name.

 label_suffix --> to change label suffix default suffix is(:).

 help_text --> to provide additional information about input.

 max_length --> can’t insert more than specified chars.

 min_length --> can’t insert less than specified chars.

 required --> if assign to false browser will not force to fill this field.

Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk Road,
Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir

Widget:

A widget is Django’s representation of an HTML input element.Whenever you specify a


field on a form, Django will use a default widget that is appropriate to the type of data
that is to be displayed.

These widgets will help to create more interactive form for any site.

Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk Road,
Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir

Default Widget in Form Fields

Every field has a default widget.


for example:
 IntegerField has a default widget of NumberInput. and used to create an HTML
code <input type = "number"> in the form.

 Charfield has a default widget of TextInput. and used to create an HTML code
<input type = "text"> the form.
Note: Django does not provide fields for input type submit and form tag.
So we have to add them explicitly inside html file.

Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk Road,
Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir

Here in above code snippet you can see input type for respective fields.

We can override the default widget of each field for various uses and add attributes.

Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk Road,
Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir

Right click on page and select view page source to see changes in html code

Adding Attributes:

Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk Road,
Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir

Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk Road,
Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir

lets apply bootstrap classes to make our form more attractive.

Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk Road,
Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir

Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk Road,
Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir

Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk Road,
Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir

Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk Road,
Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204

You might also like