简体   繁体   中英

django - how can i edit the html displayed in a form field?

I'm using bootstrap, and i'd like to set the span of some of the elements i have in a form.

so pretty much, instead of:

<input id="id_display_name" type="text" name="display_name">

i'd like to show

<input id="id_display_name" type="text" name="display_name" class="span4">

where the initial line was generated by:

{{ form.display_name }}

how do i stick the new html in?

https://docs.djangoproject.com/en/dev/ref/forms/widgets/#django.forms.Widget.attrs

display_name = forms.TextInput(attrs={'class': 'span4'})

will result in:

<input id="id_display_name" type="text" name="display_name" class="span4" />'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM