Patter's Home

Python Flask - Minimal application

For reference, in case I foul this up

Apache File (using mod_wsgi)

<VirtualHost *:80>
    ServerName dev.patter.me.uk

    WSGIDaemonProcess application user=www-data group=www-data threads=5
    WSGIScriptAlias / /home/httpd/dev/application.wsgi

    <Directory /home/httpd/dev>
        WSGIProcessGroup application
        WSGIApplicationGroup %{GLOBAL}
        Order deny,allow
        Allow from all
    </Directory>
</VirtualHost>

Application Structure

3 files in the same directory
application.wsgi - wsgi init script
main.py - wsgi calls this to start
app.py - the flask app

application.wsgi

Manually inserting the full path to our main.py

import sys
sys.path.insert(0, '/home/httpd/dev')
from main import app as application

main.py

from __future__ import absolute_import

from app import app

if __name__ == '__main__':
		app.run(__name__)

app.py

from __future__ import absolute_import, unicode_literals

from flask import Flask
app = Flask(__name__)


@app.route("/")
def root():
    return "Wow this is totally useless so far!"

	@app.route("/test")
	def test():
	        return "And this is a test url"