Django表单,当从模板标签访问时,整型字段被转换为字符串 [英] Django forms, integer field is converted to string when accessed from template tags

查看:296
本文介绍了Django表单,当从模板标签访问时,整型字段被转换为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆