I have the following in a form:
fields = ("subjectfk", "name", "about",)
labels = {"subjectfk": "Subject"}
widgets = {
"subjectfk": forms.Select(attrs={"class": "widget"}),
"name": forms.TextInput(attrs={"class": "widget"}),
"about": forms.Textarea(attrs={"class": "widget", "rows": 3}),
"marks": forms.NumberInput(attrs={"class": "widget"}),
}
and it renders:
How do replace the ugly “dashes” in the Subject field?
I am also having challenges setting range of values allowable in the “Marks
” field. I get errors when I try the following:
forms.NumberInput(min_value=0)
Output:
TypeError: Input.__init__() got an unexpected keyword argument 'min_value'
Lots of confusing blogs out there
See: Form fields | Django documentation | Django
If you want the client-side validation in the field, you should be able to use the min
attribute in the attrs
dict with the desired min value.
If you want server-side validation, see Form and field validation | Django documentation | Django
(Note, you can do both, but you want to avoid doing client-side validation only. It’s too easily bypassed.)