Usually we use forms.py and create class Form to generate form and pass it into views.py. As usual, we need to customize form in ModelForm for instance, we need to add class attribute. So, we can use Widget to solve this problem. Here are how to customize and add class attribute into form Django :
forms.py
1 2 3 4 | from django import forms class YahooParse(forms.Form): url = forms.URLField(widget=forms.TextInput(attrs={‘class’: ‘xlarge’})) |
This will generate form like this :
1 | <input type="text" name="url" class="xlarge" id="id_url"> |