Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save EdMan1022/68b011a8632fd596fe7245e75d31e36f to your computer and use it in GitHub Desktop.
Save EdMan1022/68b011a8632fd596fe7245e75d31e36f to your computer and use it in GitHub Desktop.

Revisions

  1. @Jaza Jaza revised this gist Feb 6, 2015. 2 changed files with 0 additions and 3 deletions.
    3 changes: 0 additions & 3 deletions .gitignore
    Original file line number Diff line number Diff line change
    @@ -1,3 +0,0 @@
    *.pyc
    env

  2. @Jaza Jaza revised this gist Feb 6, 2015. 3 changed files with 24 additions and 2 deletions.
    7 changes: 7 additions & 0 deletions foo/bar.py → bar.py
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,10 @@
    """
    Note: can't put in a subdirectory for this example (GitHub Gists
    doesn't allow subdirectories). Recommended to move this file to
    foo/bar.py.
    """


    routes = []


    7 changes: 7 additions & 0 deletions foo/baz.py → baz.py
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,10 @@
    """
    Note: can't put in a subdirectory for this example (GitHub Gists
    doesn't allow subdirectories). Recommended to move this file to
    foo/baz.py.
    """


    routes = []


    12 changes: 10 additions & 2 deletions foo/__init__.py → foo.py
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,11 @@
    """
    Note: can't put in a subdirectory for this example (GitHub Gists
    doesn't allow subdirectories). Recommended to move this file to
    foo/__init__.py, and to change the imports to
    'from .bar' and 'from .baz'.
    """


    from flask import Blueprint


    @@ -9,8 +17,8 @@ def home():
    return 'Foo home'


    from .bar import routes as bar_routes
    from .baz import routes as baz_routes
    from bar import routes as bar_routes
    from baz import routes as baz_routes


    routes = (
  3. @Jaza Jaza revised this gist Feb 6, 2015. 4 changed files with 66 additions and 0 deletions.
    1 change: 1 addition & 0 deletions .gitignore
    Original file line number Diff line number Diff line change
    @@ -1,2 +1,3 @@
    *.pyc
    env

    25 changes: 25 additions & 0 deletions foo/__init__.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    from flask import Blueprint


    mod = Blueprint('foo', __name__)


    @mod.route('/')
    def home():
    return 'Foo home'


    from .bar import routes as bar_routes
    from .baz import routes as baz_routes


    routes = (
    bar_routes +
    baz_routes)

    for r in routes:
    mod.add_url_rule(
    r['rule'],
    endpoint=r.get('endpoint', None),
    view_func=r['view_func'],
    **r.get('options', {}))
    20 changes: 20 additions & 0 deletions foo/bar.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    routes = []


    def ping_bar():
    return 'Ping bar'


    routes.append(dict(
    rule='/ping-bar/',
    view_func=ping_bar))


    def save_bar():
    return 'Save bar'


    routes.append(dict(
    rule='/save-bar/',
    view_func=save_bar,
    options=dict(methods=['POST',])))
    20 changes: 20 additions & 0 deletions foo/baz.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    routes = []


    def call_baz():
    return 'Call baz'


    routes.append(dict(
    rule='/call-baz/',
    view_func=call_baz))


    def delete_baz():
    return 'Delete baz'


    routes.append(dict(
    rule='/delete-baz/',
    view_func=delete_baz,
    options=dict(methods=['GET', 'POST'])))
  4. @Jaza Jaza renamed this gist Feb 6, 2015. 1 changed file with 0 additions and 0 deletions.
  5. @Jaza Jaza revised this gist Feb 6, 2015. 2 changed files with 3 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions .gitignore
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    env

    1 change: 1 addition & 0 deletions requirements.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    Flask==0.10.1
  6. @Jaza Jaza renamed this gist Feb 6, 2015. 1 changed file with 0 additions and 0 deletions.
  7. @Jaza Jaza revised this gist Feb 6, 2015. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions Flask Blueprint with imported routes
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    *
  8. @Jaza Jaza created this gist Feb 6, 2015.
    19 changes: 19 additions & 0 deletions example_app.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    from flask import Flask


    app = Flask(__name__)

    app.debug = True


    @app.route('/')
    def home():
    return 'App home'


    from foo import mod
    app.register_blueprint(mod, url_prefix='/foo')


    if __name__ == '__main__':
    app.run()