redirect-django-url-with-javascript

发布时间 2023-07-02 18:09:04作者: 花生与酒

https://www.appsloveworld.com/django/100/279/redirect-django-url-with-javascript

score:3

Accepted answer

You 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:

Syntax:

location.href="URL"
      or
location.replace("URL")
      or
location.assign("URL")