简体   繁体   English

如何在Django中的模板中检测表单字段的类型

[英]How to detect type of Form Field in Template in Django

Hi guys i have simple Django Form , but I need to get type of this field elements and I made some special operations according to this. 大家好,我有简单的Django Form,但是我需要获取此字段元素的类型,并根据此进行了一些特殊的操作。

Is there an easy way to get type of Form Field in Django Template? 有没有一种简单的方法来获取Django模板中表单字段的类型?

Any help will be appreciated. 任何帮助将不胜感激。

For your actual use case the image widget from the django-form-utils package should be a good match. 对于您的实际用例, django-form-utils包中的image小部件应该是一个很好的匹配。

On more general level: If you simply want to modify the html generated by a standard widget you should subclass the widget and tweak the render-method. 在更一般的级别上:如果您只想修改标准窗口小部件生成的html,则应将其子类化并调整渲染方法。

Take a look at this blog post to get the basic idea. 查看此博客文章以了解基本思想。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM