Folder structure and the controller object

To contain the separate components of the application, a specific folder structure is recommended. It will allow for the components to reference each other as needed, while still maintaining independence. Adjustments made to one portion of a component shouldn't require the overhaul of a separated component (at least as much as possible).

The Arena application is contained within a folder called arenaapp:

Inside the arenaapp folder is a script called app.py and a folder called application:

The app.py script imports the app controller object from the application and calls the app.run method to start the web application:

from application import app
app.run()

Making the folder application importable and allowing app access to code inside the component scripts is made possible by adding a Python __init__.py script. This special script indicates to the Python executable that the folder is a module:

Inside __init__.py, the app object is defined and configured. The app object contains a configuration dictionary that allows the web application to connect to the backend ('SQLALCHEMY_DATABASE_URI') and to perform session management and encryption. While we have included the configuration settings within this script, note that larger applications will separate out the configuration settings into a separate config.py script:

import flask
app = flask.Flask(__name__)
conn_string = 'postgresql://postgres:password@localhost:5432/chapter11'
app.config['SQLALCHEMY_DATABASE_URI'] = conn_string
app.config['SECRET_KEY'] = "SECRET_KEY"
app.config['DEBUG'] = True
import application.views

To make it easier to debug the application, the DEBUG configuration has been set to True. Set it to False in production. Replace 'SECRET KEY' with your own secret key.

Read more about configuring a Flask web application here: http://flask.pocoo.org/docs/latest/config/.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset