【问题标题】:How to get the value of an individual radio button in a Django template?如何获取 Django 模板中单个单选按钮的值?
【发布时间】:2017-06-26 17:11:18
【问题描述】:

有没有办法让模板检查单个单选按钮的值?

我知道如何获取其他属性:

{% for button in myform.radio_select %}
    {{button.tag}}
    {{button.choice_label}}
    {{button.id_for_label}}
{% endfor %}

但是我如何获得价值呢?我尝试了明显的{{button.value}} 和不太明显的{{button.tag.value}},但它们不起作用。

【问题讨论】:

    标签: django django-forms


    【解决方案1】:

    this question 的答案说,从 Django 1.11 开始,值存储在 {{button.data.value}}

    以前版本的 Django 使用 {{button.choice_value}}

    【讨论】:

      猜你喜欢
      • 2015-04-13
      • 2014-09-09
      • 2020-11-12
      • 2021-12-23
      • 1970-01-01
      • 2022-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多