In Django Templates, how do i specify the size of a field
This is my form class:
class PstForm(forms.Form):
hours = forms.ChoiceField(choices=[(6,6),(24,24),(48,48)], widget=forms.Select(attrs={'size':'3'}))
however this still renders a rather long field
how do i limit the size?
CharField in Django Forms is a string field, for small- to large-sized strings. It is used for taking text inputs from the user. The default widget for this input is TextInput.
Set the exclude attribute of the ModelForm 's inner Meta class to a list of fields to be excluded from the form.
attrs . A dictionary containing HTML attributes to be set on the rendered DateInput and TimeInput widgets, respectively. If these attributes aren't set, Widget. attrs is used instead.
Basically to extract data from a form field of a form, all you have to do is use the form. is_valid() function along with the form. cleaned_data. get() function, passing in the name of the form field into this function as a parameter.
You could try adjusting the CSS: attrs={'style': 'width:10px'}
, (or 'class': 'some-class'
, etc).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With