Flask: Lack of documentation on how to serve Flask under a non-root path

Created on 2 Feb 2016  路  8Comments  路  Source: pallets/flask

If I am not mistaken the docs lack a good description on how to setup Flask to use a different _application root path_. I summarized my current understanding in this Gist.

Also the name of Flask's APPLICATION_ROOT config variable is pretty misleading. One could wrongly assume that it affects routing (stripping away application_root) and url_for() (prepending application_root). I do not even get the point of the current APPLICATION_ROOT setting because there already is SESSION_COOKIE_PATH.

docs

Most helpful comment

@jeffwidman: This whole issue is a question. If the documentation covered this, then it would not be an issue. I'll figure it out eventually... (^_^)

All 8 comments

Were you looking at the development version of the docs or the 0.10 version?

IIRC, there have been some PRs that improved the uWSGI/Nginx deployment docs regarding deploying under a non-root path, not sure about other options: http://flask.pocoo.org/docs/dev/deploying/#deployment

Thanks for the pointer to the docs.

What is not obvious to me from this is how to reference the script's path. I do use the --virtualenvargument in my uwsgi startup call, but how can I tell the uwsgi startup call to manage the script name when I am not even telling it where the script is located. I've even tried using the uwsgi_param attributes UWSGI_PYHOME and UWSGI_CHDIR in my nginx.conf location directive, all to no avail. I keep getting a ImportError: No module named run error (run.py is where my app.run statement is).

@GregSilverman Your comment sounds more like a question and not a bug report. This issue tracker is for bugs, so if you want an answer, StackOverflow is probably a better fit.

@jeffwidman: This whole issue is a question. If the documentation covered this, then it would not be an issue. I'll figure it out eventually... (^_^)

+1. url_for() should indeed listen to APPLICATION_ROOT by prepending it, right?

@skftn no APPLICATION_ROOT only sets the path of the session cookie. When you want to serve your Flask app under a subpath, you have to tell your WSGI container the SCRIPT_NAME, see my gist.

In my pull request #2210 I added the following to the APPLICATION_ROOT configuration value:

Note that to actually serve your Flask app under a subpath you need to tell your WSGI container the SCRIPT_NAME WSGI environment variable.

@davidism, why did you remove this clarification in 60feecc26c60b8b6ba5349baf8d4cca5cbfed223? Is it wrong? Do the docs now again contain no info on how to serve Flask under a subpath?

If someone would like to add to the deployment docs showing how to serve under a non-root path, I'd be happy to review a PR.

Was this page helpful?
0 / 5 - 0 ratings