Configuring Flask Externally

Or "In before Diablo III".

I finally deployed my system last week, just before Diablo III got released and gobbled up all my free time!

There are still a few features that I still want to implement, but the core functionality is there and I'm really pleased with it.

One issue I had some trouble with was configuring my app arbitrarily. The various examples pointed to in the Flask documentation all package the settings in with the application. I wanted to be able to use the same Python package to potentially run multiple sites.

My application is set up like this:



    {static HTML generated by system}

Basically, I wanted to be able to move the site_settings.cfg file into the pyDim_system folder, meaning I could create another site later using the same application code, but pointing at a different static website.

pyDimension is configured in the file:

from flask import Flask

app = Flask(__name__)

I'm not sure why, but app.config.from_pyfile() doesn't appear to follow any sensible environment states, it just seems to look for the file in whatever directory the application lives in, ignoring the Python path and the current working directory!

It can however be fed an absolute file path, so I removed that line from and changed pyDim_system.wsgi:

import sys


from pyDimension import app as application

It's a little inelegant, but it means that configuration for the app can be done alongside configuration for the mod_wsgi script, and I can run multiple sites with the same app code in my projects directory.