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>
Source:stackexchange.com