Open braingram opened 12 years ago
#!/usr/bin/env python
import os
import flask
main_dir = os.path.dirname(os.path.abspath(__name__))
a_blueprint = flask.Blueprint('a', 'a', \
template_folder=os.path.join(main_dir, 'a'), \
static_folder=os.path.join(main_dir, 'a', 'static'))
b_blueprint = flask.Blueprint('b', 'b', \
template_folder=os.path.join(main_dir, 'b'), \
static_folder=os.path.join(main_dir, 'b', 'static'))
app = flask.Flask(__name__)
@a_blueprint.route('/')
def get_a():
return flask.render_template('index.html')
@b_blueprint.route('/')
def get_b():
return flask.render_template('index.html')
app.register_blueprint(a_blueprint, url_prefix='/a')
app.register_blueprint(b_blueprint, url_prefix='/b')
if __name__ == '__main__':
app.run(debug=True)
http://flask.pocoo.org/docs/blueprints/
Benefits
Each blueprint has it's own static and template file paths