2

Problem

I want to concatinate JavaScript variable with Django Template URL.

How

for (var i = 0; i < data.length; i++) {
    var city_url = "{% url 'explore_city' javascriptVariable templateVariable %}";
}

Howto?

Suggestions please.

0

1 Answer 1

1

This is not possible, because the django template is rendered before it ever gets to the user's browser. As an alternative, you could generate the url without using {%url ... %}. For example, you could have something like.

for (var i = 0; i < data.length; i++) {
    var templateVariable = "{{templateVariable}}";
    var city_url = "/explore-city/" + javascriptVariable + "/" + templateVariable;
}
Sign up to request clarification or add additional context in comments.

1 Comment

Can we use with oprator with JavaScript?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.