S
S
sergey2017-10-27 18:04:00
JavaScript
sergey, 2017-10-27 18:04:00

What url format to set in the script?

I am doing a tour of the site, by analogy with intro, js, and it is necessary to implement a transition to another page, using this js code:

document.getElementById('start').onclick = function() {
        introJs().setOption('doneLabel', 'Next page').start().oncomplete(function() {
            window.location.href = 'second.html?multipage=true';
        });
    };

the project is on django and therefore the url needs to be written django - I have it like this {% url 'clients:product-create' %}
If I substitute this construction instead of second.html {% url 'clients:product-create' %} - the script does not works.
How to write url here?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2017-10-27
@zorro76

Of course it doesn't work, the template engine that processes the construction {% url 'clients:product-create' %}works on the server, and the javascript works in the user's browser and has no idea how to process this. To solve this problem, there are many options. One of them is to include in the template from which the request will occur, the code of the form

<script type="text/javascript">
    window.urls = {
        clientProductCreate: {% url 'clients:product-create' %}
    }
</script>

And in the js script, get the url using the construction
Or you can use something like django-js-utils .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question