Blueprint example app
This commit is contained in:
parent
20a3281209
commit
85ad4ffb60
7 changed files with 64 additions and 0 deletions
0
examples/blueprintexample/simple_page/__init__.py
Normal file
0
examples/blueprintexample/simple_page/__init__.py
Normal file
13
examples/blueprintexample/simple_page/simple_page.py
Normal file
13
examples/blueprintexample/simple_page/simple_page.py
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
from flask import Blueprint, render_template, abort
|
||||
from jinja2 import TemplateNotFound
|
||||
|
||||
simple_page = Blueprint('simple_page', __name__,
|
||||
template_folder='templates')
|
||||
|
||||
@simple_page.route('/', defaults={'page': 'index'})
|
||||
@simple_page.route('/<page>')
|
||||
def show(page):
|
||||
try:
|
||||
return render_template('pages/%s.html' % page)
|
||||
except TemplateNotFound:
|
||||
abort(404)
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
{% extends "pages/layout.html" %}
|
||||
|
||||
{% block body %}
|
||||
Hello
|
||||
{% endblock %}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
{% extends "pages/layout.html" %}
|
||||
|
||||
{% block body %}
|
||||
Blueprint example page
|
||||
{% endblock %}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
<!doctype html>
|
||||
<title>Simple Page Blueprint</title>
|
||||
<div class=page>
|
||||
<h1>This is blueprint example</h1>
|
||||
<p>
|
||||
A simple page blueprint is registered under / and /pages<br/>
|
||||
you can access it using this urls:
|
||||
<ul>
|
||||
<li><a href="{{ url_for('simple_page.show', page='hello') }}">/hello</a></li>
|
||||
<li><a href="{{ url_for('simple_page.show', page='world') }}">/world</a></li>
|
||||
</ul>
|
||||
</p>
|
||||
<p>
|
||||
Also you can register the same blueprint under another path
|
||||
<ul>
|
||||
<li><a href="/pages/hello">/pages/hello</a></li>
|
||||
<li><a href="/pages/world">/pages/world</a></li>
|
||||
</ul>
|
||||
</p>
|
||||
|
||||
|
||||
|
||||
{% block body %}
|
||||
{% endblock %}
|
||||
</div>
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
{% extends "pages/layout.html" %}
|
||||
|
||||
{% block body %}
|
||||
World
|
||||
{% endblock %}
|
||||
Loading…
Add table
Add a link
Reference in a new issue