简体   繁体   English

在网址后附加参数“表单ID”

[英]Append parameter 'form id' with the URL

I have this code of HTML (Django + Jinja) . 我有HTML(Django + Jinja)的代码。

<div class="span10 well">

   {% for k in values.chat %}

       <label> Text : {{k.text}} </label> 
       <label> {{k.date_time}} </label>
   {% endfor %}     


   <form action = "#" method = "POST" id = {{key}} name = "reply_form">
       {% csrf_token %}
       {{ form.as_p }}

        <input type = "submit" value = "Sent" class="btn btn-primary">
   </form>

</div>

Since, there will be many chats and correspondingly reply submit button and its key, I want that when I reply to a specific chat, it carries the key with itself and process the chat accordingly. 既然会有很多聊天,并相应地答复提交按钮及其键,我希望当我回复特定的聊天时,它随身携带密钥并相应地处理聊天。

What I need is to append the url with the form id parameter. 我需要的是在URL后面附加表单id参数。 How can I achieve this? 我该如何实现?

You can create a hidden input field 您可以创建一个隐藏的输入字段

<input type="hidden" name="chat_key" value="{{key}}">

This way you can track which chatroom the person is responding by setting the value to the id of the chatroom. 这样,您可以通过将值设置为聊天室的ID来跟踪此人正在响应的聊天室。

EDIT: Since you are using django, on the backend to get the value of the chat_key you can just do this: 编辑:由于您正在使用django,在后端获取chat_key的值,您可以这样做:

chat_key = form.cleaned_data['chat_key']

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

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