Django: How do I change the HTML output of a Djang

2019-09-16 02:15发布

问题:

I have a date of birth selection of three select drop down boxes. My Django template looks like this:

<label>Date of birth</label>
{{ reg_form.date_of_birth }}

But I need to change the HTML of each element. For example I need to wrap each select element in a div individually.

I had a look for date_of_birth in the code and I found this:

date_of_birth = forms.DateField(widget=SelectDateWidget(years=range(1920, 2010)))

Is there a template somewhere that I can modify the HTML output of this?

回答1:

Perhaps not so cleanly, I solved this problem using jQuery as follows.

I targeted each of the three select elements that were generated by Django in the HTML, and then used the .wrap() function to wrap them in div elements.