Django表单,当从模板标签访问时,整型字段被转换为字符串 [英] Django forms, integer field is converted to string when accessed from template tags
问题描述
在Django表单中,如果我们提交一个无效表单,整数字段在从模板标签访问时转换为字符串字段。
(ie): Status = forms.IntegerField(max_value = 20,required = True)
使用模板标签在页面上访问
{%if form.Status.value == 1%}
做某事...
{%endif%}
是完整的问题吗?
如何访问模板标记中的整数字段?
问题(你已经知道了......)
当从模板标签访问时,整数字段转换为字符串字段
所以你的代码应该是 {%if form.Status.value =='1'%}
In Django forms, If we submit an invalid form, The integer field is converted to string field when accessed from template tags.
(i.e): Status = forms.IntegerField( max_value=20, required=True)
Accessed on page using template tags
{% if form.Status.value == 1 %}
do something...
{% endif %}
Is that full question ?
How to access integer field in template tags ?
From your question ( you already know ...
The integer field is converted to string field when accessed from template tags
So in your code should be {% if form.Status.value == '1' %}
这篇关于Django表单,当从模板标签访问时,整型字段被转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!