Is it possible to pass a template variable to a django url with jquery? I've tried the standard way of passing the parameter to the django url, but I get a no reverse match.
Javascript
<button id = "testid" href = "{%url 'test:justatest' id=8}">Click here for something</button>
<script type="text/javascript">
var btn = $('#testid');
btn.click(function (e) {
var goto = $(this).attr('href');
e.preventDefault();
$.ajax({
url: goto,
type: "GET",
success: function(data){
console.log(data);
alert(data);
}});
});
</script>
urls.py
path('test/<int:id>',views.TestDetail.as_view(),name="justatest")
I also tried this based off this post but I just get a 404.
<button id = "testid" href = "{%url 'test:justatest'%?id=8}">Click here for something</button>
<script type="text/javascript">
var btn = $('#testid');
btn.click(function (e) {
var goto = $(this).attr('href');
e.preventDefault();
$.ajax({
url: goto,
type: "GET",
success: function(data){
console.log(data);
alert(data);
}});
});
</script>