Created
January 23, 2013 16:04
-
-
Save kinsteronline/4608696 to your computer and use it in GitHub Desktop.
A sample flask app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask | |
from flask_sqlalchemy import SQLAlchemy | |
from template_app import settings | |
from template_app.core import setup_routing | |
# setup application | |
app = Flask('template_app') | |
app.config.from_object(settings) | |
import logging | |
from logging.handlers import RotatingFileHandler | |
f_handler = RotatingFileHandler('test.log') | |
f_handler.setLevel(logging.DEBUG) | |
f_handler.setFormatter(logging.Formatter( | |
'%(asctime)s %(levelname)s: %(message)s ' | |
'[in %(filename)s:%(lineno)d]' | |
)) | |
app.logger.addHandler(f_handler) | |
import yaml | |
import os | |
config = yaml.load(open('%s/template_app/config.yaml' % os.getcwd() , 'r')) | |
# setup database | |
db = SQLAlchemy(app) | |
# register application views and blueprints | |
from template_app.urls import routes | |
setup_routing(app, routes) | |
@app.teardown_request | |
def shutdown_session(exception=None): | |
db.session.remove() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment