Pass a template variable to django url using jquery
up vote
1
down vote
favorite
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>
jquery django
add a comment |
up vote
1
down vote
favorite
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>
jquery django
I think the right way to write the url would be "{%url 'justatest' '8'}". But consider passing the id via your view.
– filtfilt
Nov 4 at 10:10
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
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>
jquery django
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>
jquery django
jquery django
asked Nov 4 at 9:48
Riyaaz-0
309317
309317
I think the right way to write the url would be "{%url 'justatest' '8'}". But consider passing the id via your view.
– filtfilt
Nov 4 at 10:10
add a comment |
I think the right way to write the url would be "{%url 'justatest' '8'}". But consider passing the id via your view.
– filtfilt
Nov 4 at 10:10
I think the right way to write the url would be "{%url 'justatest' '8'}". But consider passing the id via your view.
– filtfilt
Nov 4 at 10:10
I think the right way to write the url would be "{%url 'justatest' '8'}". But consider passing the id via your view.
– filtfilt
Nov 4 at 10:10
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
I do not have experience with passing arguments like that using JS. But Looking at your code I recommend you try adding the % at the end of your statement:
“{% url ‘test:justatest’ id=8 %}”
Tell me how that goes!
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
I do not have experience with passing arguments like that using JS. But Looking at your code I recommend you try adding the % at the end of your statement:
“{% url ‘test:justatest’ id=8 %}”
Tell me how that goes!
add a comment |
up vote
0
down vote
I do not have experience with passing arguments like that using JS. But Looking at your code I recommend you try adding the % at the end of your statement:
“{% url ‘test:justatest’ id=8 %}”
Tell me how that goes!
add a comment |
up vote
0
down vote
up vote
0
down vote
I do not have experience with passing arguments like that using JS. But Looking at your code I recommend you try adding the % at the end of your statement:
“{% url ‘test:justatest’ id=8 %}”
Tell me how that goes!
I do not have experience with passing arguments like that using JS. But Looking at your code I recommend you try adding the % at the end of your statement:
“{% url ‘test:justatest’ id=8 %}”
Tell me how that goes!
answered Nov 4 at 11:08
Felix
597
597
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53139515%2fpass-a-template-variable-to-django-url-using-jquery%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
I think the right way to write the url would be "{%url 'justatest' '8'}". But consider passing the id via your view.
– filtfilt
Nov 4 at 10:10