【问题标题】:Django fieldset.html customization. How to customize a single field?Django fieldset.html 自定义。如何自定义单个字段?
【发布时间】:2010-11-25 19:45:29
【问题描述】:

在我的应用程序中,我需要将 javascript 添加到管理模板“fieldset.html”,以便为单个字段创建小部件。 但是,在字段迭代(for)中,当我尝试捕获特定字段时,我失败了。

我是按 ifequal 标签(fieldset.html)做的:

    {% for line in fieldset %}
    <div class="form-row{% if line.errors %} errors{% endif %}{% for field in line %} {{ field.field.name }}{% endfor %}">

        {% for field in line %}
        (...)
            {% ifequal field.label_tag "name" %}

                  #do something

            {% endifequal%}

         (...)
        {% endfor %}
     </div>
    {% endfor %}

有什么建议吗?该字段存储计划的重复。所以我需要做一些动态的事情,这就是我考虑使用 javascript 的原因。

【问题讨论】:

  • 如果您只需要为单个字段包含一些 js 媒体,最好将表单媒体视为 ignacio propsed,如果您想检查模板中的特定字段,最好使用@987654322 检查@比label_tag...

标签: django templates field


【解决方案1】:

【讨论】:

    猜你喜欢
    • 2015-01-26
    • 2014-01-12
    • 2017-12-17
    • 2020-08-09
    • 2015-09-14
    • 2018-06-11
    • 1970-01-01
    • 2021-06-07
    • 2012-12-11
    相关资源
    最近更新 更多