如何将javascript函数的返回值保存在django模板变量中?

如何将javascript函数的返回值保存在django模板变量中?,javascript,django,onclick,Javascript,Django,Onclick,有人能帮我吗 我正在用django做评论功能,我停止了,因为我不知道怎么做 我的想法是在点击“RESPONDER”按钮时,为每个评论设置一个带有comment.id的变量值,并将其保存到django模板变量中,以便在发布答案后访问它 当您单击按钮时,将显示表单,显示CSS类和锚链接 post.html: {% for comment in comments %} <input class="blog__answer__reply" type="button" name="comment

有人能帮我吗

我正在用django做评论功能,我停止了,因为我不知道怎么做

我的想法是在点击“RESPONDER”按钮时,为每个评论设置一个带有
comment.id
的变量值,并将其保存到django模板变量中,以便在发布答案后访问它

当您单击按钮时,将显示表单,显示CSS类和锚链接

post.html:

{% for comment in comments %}
  <input class="blog__answer__reply" type="button" name="comment_parent_id" onclick="comment_parent_id=set_comment_parent_id({{ comment.id|escapejs }})" value="RESPONDER">
{% endfor %}
{% for comment in comments %}
  <input class="blog__answer__reply" type="button" name="comment_parent_id" onclick="comment_parent_id=set_comment_parent_id({{ comment.id|escapejs }})" value="RESPONDER">
{% endfor %}
functions.js:

function set_comment_parent_id(comment_id) {
  return comment_id
}
function set_comment_parent_id(comment_id) {
  return comment_id
}
解决

post.html:

{% for comment in comments %}
  <input class="blog__answer__reply" type="button" name="comment_parent_id" onclick="comment_parent_id=set_comment_parent_id({{ comment.id|escapejs }})" value="RESPONDER">
{% endfor %}
{% for comment in comments %}
  <input class="blog__answer__reply" type="button" name="comment_parent_id" onclick="comment_parent_id=set_comment_parent_id({{ comment.id|escapejs }})" value="RESPONDER">
{% endfor %}
functions.js:

function set_comment_parent_id(comment_id) {
  return comment_id
}
function set_comment_parent_id(comment_id) {
  return comment_id
}