如何在 Django 中获取表单字段的 id [英] How to get form fields' id in Django

查看:30
本文介绍了如何在 Django 中获取表单字段的 id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法获取模板中字段的id?

Is there any way to get the id of a field in a template?

在 HTML 中我得到:<input name="field_name" id="id_field_name"...

In the HTML I get: <input name="field_name" id="id_field_name"...

我知道我可以使用 {{ field.html_name }} 获取名称,但是是否有类似的方法可以获取 id?
或者我只能这样得到它:id_{{ field.html_name }}?

I know I can get the name with {{ field.html_name }}, but is there anything similar for getting the id?
Or can I only get it like this: id_{{ field.html_name }}?

推荐答案

你可以这样获取ID:

{{ field.auto_id }}

这篇关于如何在 Django 中获取表单字段的 id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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