Issue
I am hosting a flask application on a machine where there are different flask applications, on different ports. In front of them there is nginx which act as a reverse proxy so that depending on the url prefix it redirects the requests to the proper port (i.e. application).
So for instance all requests to my_ip/app1/..
are redirected to my_ip:port1
and so on.
My flask app is running via gunicorn.
I have set the SCRIPT_NAME
variable to app1
, all the links inside the app are relative links and they do not contain the prefix app1, but this is automatically added and they work fine.
The problem is that this does not happen with the get and post ajax requests which I make via jquery.
Initially the urls in these requests were just the relative paths, like distribution?a=1..
, then I replaced them with {{ url_for('distribution') }}?a=1..
, but nothing changed.
I don't understand why url_for
adds the prefix for instance to the links to the css and js file in the head and not to these links inside the js code.
I hope there is a better way than harcoding the prefix, which would make the code less portable
Solution
At the end solution was pretty simple, just use url_for('main.get_distribution')
, so specify the name of the function associated with the route.
In this way the SCRIPT_NAME prefix is correctly prefixed to the url
Answered By - Vitto
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.