Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use flask Blueprints for templates (views) #2

Open
braingram opened this issue Mar 20, 2012 · 1 comment
Open

Use flask Blueprints for templates (views) #2

braingram opened this issue Mar 20, 2012 · 1 comment

Comments

@braingram
Copy link
Owner

http://flask.pocoo.org/docs/blueprints/

Benefits

Each blueprint has it's own static and template file paths

@braingram
Copy link
Owner Author

#!/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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant