Answer the question
In order to leave comments, you need to log in
How to create a custom form?
Good day. I'm learning Django and got to forms. I did not fully understand how to create my own forms with css styles. Most examples show how to make simple forms without css styles. Can you give an example of a form with styles? Thanks in advance.
Answer the question
In order to leave comments, you need to log in
The first option is elementary:
.some-class input[type="text"] {
width: 100%;
}
.some-class input[name="some_input"] {
border: 1px solid red;
}
<form class="some-class">
{{ form }}
</form>
class SomeForm(forms.Form):
some_input = forms.CharField(label='Какое-то поле', widget=forms.TextInput(attrs={'class': 'some-class'}))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question