0

I've inherited a Flask application run using mod_wsgi on an apache server. It came with no debugging setup, so I whipped up a quick debugging script to run the app using the werkzeug.run_simple() method. I'm having issues with porting two mod_wsgi options over to the script.

WSGIPythonPath seems like the simpler one. I'm not quite sure how it works, but does this basically append the specified paths to PYTHONPATH environment variable?

WSGIScriptAlias is the more problematic one. In the apache config it's pretty standard:

WSGIScriptAlias /myapp /path/to/myapp.wsgi

This turns app.route('/login') to /myapp/login in the URL. How do I prefix all URLs with /myapp in the wsgi script in the same manner as WSGIScriptAlias?

Let me know if you need more info and thanks in advance.

1 Answer 1

1

WSGIPythonPath does indeed append modules to the system path. According to its docs it does the equivalent of running site.addsitedir for every entry (unless you are running mod_wsgi 1.x, in which case it did the equivalent of sys.path.append):

import site

for p in list_of_paths:
    site.addsitedir(p)

This adds each entry to sys.path and it also scans the directory for .pth files and adds the entries in any such files it finds to sys.path as well (which means eggs will work as expected).

For WSGIScriptAlias you can simply set the configuration variable APPLICATION_ROOT in the Flask app's config:

app.config["APPLICATION_ROOT"] = "/myapp"
Sign up to request clarification or add additional context in comments.

2 Comments

Even in mod_wsgi 1.X it more or less did the same thing. It did it by sys.path.append() though which means .pth files were not honoured.
@GrahamDumpleton - you're absolutely right - I've updated the sentence to be clear. Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.