[Fixed]-Using django template logic in loaded JS files (integrate django JS)

1👍

{% url 'index:new-article' %} will return the raw string, you have to quote its output for it to be valid Javascript.

<script>
{% if not articles %}
    var url = '{% url 'index:new-article' %}';

    $('body').on('click',function(e){
        window.location = url
    });
    ;
{% endif %}

</script>
👤frank

Leave a comment