使用javascript在django表单中设置操作

使用javascript在django表单中设置操作,javascript,jquery,html,django,post,Javascript,Jquery,Html,Django,Post,在django 1.10中,我需要将一个html模板中的参数传递回view.py,最后再次呈现相同的视图 问题在于将html中的操作设置为使用javascript 这是我的html模板: <form method='POST' action='/res/{{link}}/{{page_id}}/{{email}}/'> <input type="hidden" name="email" value="{{email}}"> <input t

django 1.10
中,我需要将一个html模板中的参数传递回
view.py
,最后再次呈现相同的视图

问题在于将html中的
操作设置为使用javascript

这是我的html模板:

<form method='POST' action='/res/{{link}}/{{page_id}}/{{email}}/'> 
      <input type="hidden" name="email" value="{{email}}">
      <input type="image" type='submit' src={% static "assets/images/twitter_icon.png" %}>
</form> 
我尝试将
操作
动态设置为:

<form method='POST' action='post_redirect_link()'> 
      <input type="hidden" name="email" value="{{email}}">
      <input type="image" type='submit' src={% static "assets/images/twitter_icon.png" %}>
</form> 

但是,我得到的重定向类型是
/res/correct\u link/post\u redirect\u link()/correct\u email
,其中“post\u redirect\u link()”作为字符串,而不是js方法返回的值


有什么建议吗?

试着做以下事情

<form action="#" method='POST'>
  <script>
     function changeAction() {
         var page_id = document.getElementById("sel1").options.selectedIndex;
         var url = '/res/{{link}}/'+page_id+'/{{email}}/';
         document.forms[0].action = url;
     }
  </script>
  <input type="hidden" name="email" value="{{email}}">
  <input type="image" type='submit' onmouseover="changeAction()" src={% static "assets/images/twitter_icon.png" %}>

</form>

函数changeAction(){
var page_id=document.getElementById(“sel1”).options.selectedIndex;
var url='/res/{{link}}/'+page_id+'/{{email}}/';
document.forms[0]。action=url;
}
尝试执行
,在函数中,您可以对所需的任何地址进行
post
调用。
<form action="#" method='POST'>
  <script>
     function changeAction() {
         var page_id = document.getElementById("sel1").options.selectedIndex;
         var url = '/res/{{link}}/'+page_id+'/{{email}}/';
         document.forms[0].action = url;
     }
  </script>
  <input type="hidden" name="email" value="{{email}}">
  <input type="image" type='submit' onmouseover="changeAction()" src={% static "assets/images/twitter_icon.png" %}>

</form>