Django ChoiceField当前被选中 [英] Django ChoiceField get currently selected

查看:138
本文介绍了Django ChoiceField当前被选中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的ChoiceField,并希望在我的模板渲染期间访问'选定的项目。

I have a simple ChoiceField and want to access the 'selected' item during my template rendering.

让我们说表单再次显示(由于一个错误的字段),有没有办法做一些像:

Lets say the form gets show again (due to error in one of the fields), is there a way to do something like:

<h1> The options you selected before was # {{ MyForm.delivery_method.selected }} </h1>

(。selected()不工作..)

(.selected() is not working..)

谢谢!

推荐答案

它将被 {{myform.delivery_method.data }}

<h1> The options you selected before was # {{ MyForm.delivery_method.data }} </h1>

这篇关于Django ChoiceField当前被选中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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