How does Django's form work with the CSS selector?

Django automatically renders the {{form}} tag in the html file into a corresponding tag < label > and input box < input >. If you want to decorate with CSS, how should the selector choose? Using input as the name of the selector directly has no effect.

Mar.19,2021

class MyForm(forms.Form):
    myfield = forms.CharField(widget=forms.TextInput(attrs={'class' : 'myfieldclass'}))

just add the above code to the field definition parameters of the class in your forms.

see https://stackoverflow.com/que.

Menu