views:

180

answers:

1

I have an input field that is rendered with a template like so:

<div class="field">
   {{ form.city }}
</div>

Which is rendered as:

<div class="field">
    <input id="id_city" type="text" name="city" maxlength="100" />
</div>

Now suppose I want to add an autocomplete="off" attribute to the input element that is rendered, how would I do that? Or onclick="xyz()" or class="my-special-css-class"?

+3  A: 

Check this page

city = forms.CharField(widget=forms.TextInput(attrs={'autocomplete':'off'}))
Galen
Ok thank you. In my case I am using ModelForm so I am not explicitly defining the form fields (e.g. class AddressForm(forms.ModelForm): class Meta: model = models.Address) Does this mean I can't use ModelForm or is there something special I need to do?
User
ok nevermind, rtfm: http://docs.djangoproject.com/en/dev/topics/forms/modelforms/
User
The django docs are a maze. It's easy to get lost
Galen