https://www.appsloveworld.com/django/100/279/redirect-django-url-with-javascript
score:3
Accepted answerYou can use this:
window.location.href = "{% url'app:result' %}"
score:1
django template tags work inside the django templates. Since you have above javascript in the app.js
file, this {% url'app:result' %}
tag in the line below won't work because it is not valid javascript.
return window.location.replace("{% url'app:result' %}")
You can try moving the code from app.js into the corresponding django template and see if that works
https://www.geeksforgeeks.org/how-to-redirect-to-another-webpage-using-javascript/
There are several methods to redirect to another webpage using JavaScript. Some of them are listed below:
- location.href: It is used to set or return the complete URL of the current page.
- location.replace(): It is used to replace the current document with the specified one.
- location.assign(): It is used for loading a new document.
Syntax:
location.href="URL" or location.replace("URL") or location.assign("URL")标签:redirect,url,app,javascript,django,location From: https://www.cnblogs.com/lxgbky/p/17521123.html