在Django中发布请求后,如何获取表单名称? [英] How do I get the name of a form after a post request in django?
本文介绍了在Django中发布请求后,如何获取表单名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<form method="post" name="message_frm">{% csrf_token %}
<input type="hidden" name="post_id" value="{{post.id}}">
{{message_frm.as_p}}
<input type="submit" value="Reply"/
我只是想知道如何验证POST请求期间发送的表单是名称为 message_frm的表单
I just wanted to know how I can verify that the form that was sent during a POST request was a form with the name of "message_frm"
谢谢
推荐答案
您可以将 name
设置为 submit
按钮,如下所示:
you can set name
in name attribute of submit
button like this:
<input type="submit" value="Reply" name ="message_frm">
,在 views.py
中,您可以进行确认表单
像这样:
and in views.py
you can recongnize form
like this:
if 'message_frm' in request.POST:
#do somethings
这篇关于在Django中发布请求后,如何获取表单名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文