Home > OS >  Is there a way to use django url template in json_script?
Is there a way to use django url template in json_script?

Time:10-17

trying to find a way to save a url into a json script but its not rendering and reading it literally unlike other values:

Tried this way

{{ "{% url 'tutorhomepage:tutorSelectedDay' tutor_id selected_date%}" | json_script:"url_test"}}

And this way:

{{ url_test | json_script:"{% url 'tutorhomepage:tutorSelectedDay' tutor_id selected_date%}"}}

But still comes out like this:

<script id="url_test" type="application/json">"{% url 'tutorhomepage:tutorSelectedDay' tutor_id selected_date%}"</script>

CodePudding user response:

You can store this in a variable:

{% url 'tutorhomepage:tutorSelectedDay' tutor_id selected_date as myurl %}
{{ myurl|json_script:"url_test" }}
  • Related