Django-crispy-form: add HTML element inside of `Field` class

时间:2016-11-09 08:18:32

标签: django django-crispy-forms

This is default HTML structure when using Field class of django-crispy-form.

Field(
    'need_meeting',
    autocomplete='off',
    id='need-meeting',
),  

.html

<div class="form-group"> 
    <div id="div_id_need_meeting" class="checkbox"> 
        <label for="need-meeting" class=""> 
            <input autocomplete="off" checked="checked" class="checkboxinput" id="need-meeting" name="need_meeting" type="checkbox"> 
             현금영수증 발행 
        </label> 
    </div> 
</div>

But what I want to do is to add some elements(<i></i>) inside of label element like this:

<div class="form-group"> 
    <div id="div_id_need_meeting" class="checkbox"> 
        <label for="need-meeting" class=""> 
            <input autocomplete="off" checked="checked" class="checkboxinput" id="need-meeting" name="need_meeting" type="checkbox"> 
             <i></i>현금영수증 발행 
        </label> 
    </div> 
</div>

I have no idea even I searched for 2hours.

Need your help.

Thanks

1 个答案:

答案 0 :(得分:0)

您可以使用crispy-form-helper将HTML插入表单 这个教程似乎很直观。我不是很擅长,但我使用它几次,它帮助我自定义布局。