首页 > 其他 > 详细

自定制插件widget 组件

时间:2020-05-04 13:48:21      阅读:50      评论:0      收藏:0      [点我收藏+]
技术分享图片
from django.forms.widgets import RadioSelect

class ColorRadioSelect(RadioSelect):
    # input_type = ‘radio‘
    # template_name = ‘django/forms/widgets/radio.html‘
    # option_template_name = ‘django/forms/widgets/radio_option.html‘

    template_name = widgets/radio.html
    option_template_name = widgets/radio_option.html
widget.py
技术分享图片
{% with id=widget.attrs.id %}
{#    定义id变量 id=widget.attrs.id#}
    <div{% if id %} id="{{ id }}"{% endif %}{% if widget.attrs.class %} class="{{ widget.attrs.class }}"{% endif %}>
        {% for group, options, index in widget.optgroups %}


        {% for option in options %}
            <label {% if option.attrs.id %}for=" {{ option.attrs.id }}"{% endif %}>
                {% include option.template_name with widget=option %}
            </label>

        {% endfor %}


        {% endfor %}
    </div>
{% endwith %}
radio.html
技术分享图片
{% include "django/forms/widgets/input.html" %}
<span class="cycle" style="background-color:{{ option.label }}"></span>
radio_option.html

 

自定制插件widget 组件

原文:https://www.cnblogs.com/hude/p/12826055.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!