Configuration file for Flask application
Question: _I'm new to Python, so please bear with me._

I am attempting to create a file in which to store my configuration settings
in a Flask project. However, I seem to be getting errors when I attempt to
import the file.

Here's my configuration file (location: `app/config.py`):

    
    
    database_uri = 'something here'
    secret_key = something here"
    

And here's where I'm using it (location: `app/models.py`):

    
    
    from app import config
    ...
    app.config['SQLALCHEMY_DATABASE_URI'] = config.database_uri
    

However, I seem to be getting this error when launching the application:

    
    
    [Sat Aug 08 19:00:15.539773 2015] [:error] [pid 29784] [client 188.183.57.54:64122] mod_wsgi (pid=29784): Target WSGI script '/var/www/pwforum/pwforum.wsgi' cannot be loaded as Python module.
    [Sat Aug 08 19:00:15.540014 2015] [:error] [pid 29784] [client 188.183.57.54:64122] mod_wsgi (pid=29784): Exception occurred processing WSGI script '/var/www/pwforum/pwforum.wsgi'.
    [Sat Aug 08 19:00:15.540146 2015] [:error] [pid 29784] [client 188.183.57.54:64122] Traceback (most recent call last):
    [Sat Aug 08 19:00:15.540250 2015] [:error] [pid 29784] [client 188.183.57.54:64122]   File "/var/www/pwforum/pwforum.wsgi", line 7, in <module>
    [Sat Aug 08 19:00:15.540448 2015] [:error] [pid 29784] [client 188.183.57.54:64122]     from app import app as application
    [Sat Aug 08 19:00:15.540537 2015] [:error] [pid 29784] [client 188.183.57.54:64122]   File "/var/www/pwforum/app/__init__.py", line 12, in <module>
    [Sat Aug 08 19:00:15.540685 2015] [:error] [pid 29784] [client 188.183.57.54:64122]     from app import views, models
    [Sat Aug 08 19:00:15.540773 2015] [:error] [pid 29784] [client 188.183.57.54:64122]   File "/var/www/pwforum/app/views.py", line 3, in <module>
    [Sat Aug 08 19:00:15.541061 2015] [:error] [pid 29784] [client 188.183.57.54:64122]     from app.models import db, User, Category, Topic, Post
    [Sat Aug 08 19:00:15.541154 2015] [:error] [pid 29784] [client 188.183.57.54:64122]   File "/var/www/pwforum/app/models.py", line 11, in <module>
    [Sat Aug 08 19:00:15.541333 2015] [:error] [pid 29784] [client 188.183.57.54:64122]     app.config['SQLALCHEMY_DATABASE_URI'] = config.database_uri
    [Sat Aug 08 19:00:15.541413 2015] [:error] [pid 29784] [client 188.183.57.54:64122] AttributeError: 'module' object has no attribute 'database_uri'
    


Answer: Your config file should look like this:

    
    
    SQLALCHEMY_DATABASE_URI = '<your-db-driver>://<user>:<pw>@<db-url>'
    SECRET_KEY = '<your-very-secret-key>'
    

Then you can do:

    
    
    app = Flask(__name__)
    app.config.from_object('config')
    

