I have forms.py file with usercreation form inside of it. It works just fine, but the only way I can display fields in it(first_name, last_name, username, email, password and password confirmation is by writing {{ form.as_p }}. I want to display it the way I could style it. Are there any ways to do that?
CodePudding user response:
You can add the css style by using form widgets
class BasicForm(forms.Form):
first_name = models.CharField(...,
widget=forms.TextInput(attrs={'class' : 'myclass'})
last_name = models.CharField(...,
widget=forms.TextInput(attrs={'class' : 'myfieldclass'})
later use class css design
CodePudding user response:
You can write your own HTML at various degrees of granularity. It's described in the documentation.
Crispy Forms is a widely used package that makes fancy form layout a lot easier. Also you can do most of the work in Python by coding a Crispy Layout object, rather than by writing a complicated HTML template.