User User - 9 months ago 23
HTML Question

Django: How do I add arbitrary html attributes to input fields on a form?

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

<div class="field">
{{ }}

Which is rendered as:

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

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"?


Check this page

city = forms.CharField(widget=forms.TextInput(attrs={'autocomplete':'off'}))