Skip to content
Myr

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

8 files+100 added−0 removed

added:examples/blueprintexample/simple_page/templates/pages/hello.html+5 added
added:examples/blueprintexample/simple_page/templates/pages/index.html+5 added
added:examples/blueprintexample/simple_page/templates/pages/layout.html+25 added
added:examples/blueprintexample/simple_page/templates/pages/world.html+5 added
added:examples/blueprintexample/simple_page/__init__.py
added:examples/blueprintexample/simple_page/simple_page.py+13 added
1from flask import Blueprint, render_template, abort2from jinja2 import TemplateNotFound34simple_page = Blueprint('simple_page', __name__,5 template_folder='templates')67@simple_page.route('/', defaults={'page': 'index'})8@simple_page.route('/<page>')9def 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 ~~~~~~~~~~~~~~56 Tests the Blueprint example app7"""8import blueprintexample9import unittest101112class BlueprintExampleTestCase(unittest.TestCase):1314 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 35if __name__ == '__main__':36 unittest.main()
added:examples/blueprintexample/blueprintexample.py+11 added
1from flask import Flask2from simple_page.simple_page import simple_page34app = Flask(__name__)5app.register_blueprint(simple_page)6# Blueprint can be registered many times7app.register_blueprint(simple_page, url_prefix='/pages') 8910if __name__ == '__main__':11 app.run(debug=True)