zoukankan      html  css  js  c++  java
  • 自定制插件widget 组件

    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
  • 相关阅读:
    「2019冬令营提高组」原样输出
    FJWC2019
    P2763 试题库问题
    P3979 遥远的国度
    P2754 [CTSC1999]家园
    P1251 餐巾计划问题
    P1382 楼房
    P1384 幸运数与排列
    P4294 [WC2008]游览计划
    P3345 [ZJOI2015]幻想乡战略游戏
  • 原文地址:https://www.cnblogs.com/hude/p/12826055.html
Copyright © 2011-2022 走看看