Skip to content
Myr

Added a minimal blueprint example

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Armin Ronacher · committed by Armin Ronacher · parent 3b313b1 · Browse files · 1 file+19 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+19 added−0 removed

  • other:+19 added−0 removed

1 file+19 added−0 removed

modified:docs/blueprints.rst+19 added
39 unmodified lines
40additionally each time a request gets dispatched to a view that was41declared to a blueprint Flask will remember that the request was42dispatched to that blueprint. That way it's easier to generate URLs from43one endpoint to another in the same module.4445My First Blueprint46------------------4748This is what a very basic blueprint looks like. In this case we want to49implement a blueprint that does simple rendering of static templates::5051 from flask import Blueprint, render_template, abort52 from jinja2 import TemplateNotFound5354 simple_page = Blueprint('simple_page', __name__)5556 @simple_page.route('/', defaults={'page': 'index'})57 @simple_page.route('/<page>')58 def show(page):59 try:60 return render_template('simple_pages/%s.html' % page)61 except TemplateNotFound:62 abort(404)