mirror of https://github.com/pallets/flask.git
Added a migrated moduleapp as blueprint app
This commit is contained in:
parent
e17e74d3a7
commit
37fab78887
|
|
@ -0,0 +1,7 @@
|
||||||
|
from flask import Flask
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
from moduleapp.apps.admin import admin
|
||||||
|
from moduleapp.apps.frontend import frontend
|
||||||
|
app.register_blueprint(admin)
|
||||||
|
app.register_blueprint(frontend)
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
from flask import Blueprint, render_template
|
||||||
|
|
||||||
|
admin = Blueprint(__name__, url_prefix='/admin')
|
||||||
|
|
||||||
|
|
||||||
|
@admin.route('/')
|
||||||
|
def index():
|
||||||
|
return render_template('admin/index.html')
|
||||||
|
|
||||||
|
|
||||||
|
@admin.route('/index2')
|
||||||
|
def index2():
|
||||||
|
return render_template('./admin/index.html')
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
/* nested file */
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
Admin File
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
Hello from the Admin
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
from flask import Blueprint, render_template
|
||||||
|
|
||||||
|
frontend = Blueprint(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
@frontend.route('/')
|
||||||
|
def index():
|
||||||
|
return render_template('frontend/index.html')
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
Hello from the Frontend
|
||||||
|
|
@ -433,7 +433,7 @@ class BasicFunctionalityTestCase(unittest.TestCase):
|
||||||
def test_teardown_request_handler_debug_mode(self):
|
def test_teardown_request_handler_debug_mode(self):
|
||||||
called = []
|
called = []
|
||||||
app = flask.Flask(__name__)
|
app = flask.Flask(__name__)
|
||||||
app.debug = True
|
app.testing = True
|
||||||
@app.teardown_request
|
@app.teardown_request
|
||||||
def teardown_request(exc):
|
def teardown_request(exc):
|
||||||
called.append(True)
|
called.append(True)
|
||||||
|
|
@ -819,7 +819,7 @@ class JSONTestCase(unittest.TestCase):
|
||||||
|
|
||||||
def test_json_body_encoding(self):
|
def test_json_body_encoding(self):
|
||||||
app = flask.Flask(__name__)
|
app = flask.Flask(__name__)
|
||||||
app.debug = True
|
app.testing = True
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def index():
|
def index():
|
||||||
return flask.request.json
|
return flask.request.json
|
||||||
|
|
@ -1139,7 +1139,7 @@ class ModuleTestCase(unittest.TestCase):
|
||||||
|
|
||||||
def test_templates_and_static(self):
|
def test_templates_and_static(self):
|
||||||
app = moduleapp
|
app = moduleapp
|
||||||
app.debug = True
|
app.testing = True
|
||||||
c = app.test_client()
|
c = app.test_client()
|
||||||
|
|
||||||
rv = c.get('/')
|
rv = c.get('/')
|
||||||
|
|
@ -1293,6 +1293,36 @@ class BlueprintTestCase(unittest.TestCase):
|
||||||
self.assertEqual(c.get('/1/bar').data, u'23')
|
self.assertEqual(c.get('/1/bar').data, u'23')
|
||||||
self.assertEqual(c.get('/2/bar').data, u'19')
|
self.assertEqual(c.get('/2/bar').data, u'19')
|
||||||
|
|
||||||
|
def test_templates_and_static(self):
|
||||||
|
from blueprintapp import app
|
||||||
|
c = app.test_client()
|
||||||
|
|
||||||
|
rv = c.get('/')
|
||||||
|
assert rv.data == 'Hello from the Frontend'
|
||||||
|
rv = c.get('/admin/')
|
||||||
|
assert rv.data == 'Hello from the Admin'
|
||||||
|
rv = c.get('/admin/index2')
|
||||||
|
assert rv.data == 'Hello from the Admin'
|
||||||
|
rv = c.get('/admin/static/test.txt')
|
||||||
|
assert rv.data.strip() == 'Admin File'
|
||||||
|
rv = c.get('/admin/static/css/test.css')
|
||||||
|
assert rv.data.strip() == '/* nested file */'
|
||||||
|
|
||||||
|
with app.test_request_context():
|
||||||
|
assert flask.url_for('admin.static', filename='test.txt') \
|
||||||
|
== '/admin/static/test.txt'
|
||||||
|
|
||||||
|
with app.test_request_context():
|
||||||
|
try:
|
||||||
|
flask.render_template('missing.html')
|
||||||
|
except TemplateNotFound, e:
|
||||||
|
assert e.name == 'missing.html'
|
||||||
|
else:
|
||||||
|
assert 0, 'expected exception'
|
||||||
|
|
||||||
|
with flask.Flask(__name__).test_request_context():
|
||||||
|
assert flask.render_template('nested/nested.txt') == 'I\'m nested'
|
||||||
|
|
||||||
|
|
||||||
class SendfileTestCase(unittest.TestCase):
|
class SendfileTestCase(unittest.TestCase):
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue