Merge pull request #413 from dmishe/master
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Blueprint example app
authored by Kenneth Reitz · committed by Kenneth Reitz · parents ddeeca7, 62621cc · Browse files · 8 files·+100 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
8 files+100 added−0 removed
- other:+100 added−0 removed
Provenance
- Commit
0ba758d- Tree
4beb84b- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent 1
ddeeca7- Parent 2
62621cc
8 files changed+100 added−0 removed
added:examples/blueprintexample/simple_page/templates/pages/hello.html+5 added
12345{% extends "pages/layout.html" %}
{% block body %} Hello{% endblock %}No newline at end of fileadded:examples/blueprintexample/simple_page/templates/pages/index.html+5 added
12345{% extends "pages/layout.html" %}
{% block body %} Blueprint example page{% endblock %}No newline at end of fileadded:examples/blueprintexample/simple_page/templates/pages/layout.html+25 added
12345678910111213141516171819202122232425<!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>No newline at end of fileadded:examples/blueprintexample/simple_page/templates/pages/world.html+5 added
12345{% extends "pages/layout.html" %}
{% block body %} World{% endblock %}No newline at end of fileadded:examples/blueprintexample/simple_page/__init__.py
added:examples/blueprintexample/simple_page/simple_page.py+13 added
1+from flask import Blueprint, render_template, abort2+from jinja2 import TemplateNotFound3+4+simple_page = Blueprint('simple_page', __name__,5+ template_folder='templates')6+7+@simple_page.route('/', defaults={'page': 'index'})8+@simple_page.route('/<page>')9+def show(page):10+ try:11+ return render_template('pages/%s.html' % page)12+ except TemplateNotFound:13+ abort(404)added:examples/blueprintexample/blueprintexample_test.py+36 added
1+# -*- coding: utf-8 -*-2+"""3+ Blueprint Example Tests4+ ~~~~~~~~~~~~~~5+6+ Tests the Blueprint example app7+"""8+import blueprintexample9+import unittest10+11+12+class BlueprintExampleTestCase(unittest.TestCase):13+14+ def setUp(self):15+ self.app = blueprintexample.app.test_client()16+ 17+ def test_urls(self):18+ r = self.app.get('/')19+ self.assertEquals(r.status_code, 200)20+ 21+ r = self.app.get('/hello')22+ self.assertEquals(r.status_code, 200)23+ 24+ r = self.app.get('/world')25+ self.assertEquals(r.status_code, 200)26+ 27+ #second blueprint instance28+ r = self.app.get('/pages/hello')29+ self.assertEquals(r.status_code, 200)30+ 31+ r = self.app.get('/pages/world')32+ self.assertEquals(r.status_code, 200)33+ 34+ 35+if __name__ == '__main__':36+ unittest.main()added:examples/blueprintexample/blueprintexample.py+11 added
1+from flask import Flask2+from simple_page.simple_page import simple_page3+4+app = Flask(__name__)5+app.register_blueprint(simple_page)6+# Blueprint can be registered many times7+app.register_blueprint(simple_page, url_prefix='/pages') 8+9+10+if __name__ == '__main__':11+ app.run(debug=True)