Django: How can I call a view function from template? -


i have question on how call view function template html button? onclick function? here template:

<input id="submit" type="button" onclick="xxx" method="post" value="click" /> 

and views.py is:

def request_page(request):     ...do something...     return render_to_response("/directory.html", {}) 

thank much.

one option is, can wrap submit button form

something this:

<form action="{% url path.to.request_page %}" method="post">     <input id="submit" type="button" value="click" /> </form> 

(remove onclick , method)

if want load specific part of page, without page reload - can do

<input id="submit" type="button" value="click" data_url/> 

and on submit listener

$(function(){      $('form').on('submit', function(e){          e.preventdefault();          $.ajax({              url: $(this).attr('action'),              method: $(this).attr('method'),              success: function(data){ $('#target').html(data) }          });      }); }); 

Comments