[Answered ]-Django : Fetch API redirects to wrong URL

0πŸ‘

βœ…

Had the same problem. Although i dont think this is the best way, try http://127.0.0.1:8000/recommend_product

πŸ‘€04k

1πŸ‘

I would guess it’s something to do with how Django processes requests.

Your url is only defined as var url = '/recommend_product/', so it may be going to '127.0.0.1:8000/store/recommend_product/' by default if /store is your first defined url path.

Edit: To correct it, be more specific with your url

var url = 'http://127.0.0.1:8000/recommend_product/'

πŸ‘€BStarcheus

0πŸ‘

I had a similar error on my projects.
Your best bet might be to use javascript, as in ${window.location.host}/your_endpoint/.
This would make it quite dynamic.

πŸ‘€Zedtek

Leave a comment