-
Notifications
You must be signed in to change notification settings - Fork 8
Commit v0.7
kwmccabe edited this page Apr 17, 2018
·
9 revisions
v0.7 - Blueprint modules: main, item
- +8 -0 [M] web/app/init.py
- +5 -0 [A] web/app/item/init.py
- +10 -0 [A] web/app/item/views.py
- +5 -0 [A] web/app/main/init.py
- +34 -0 [A] web/app/main/views.py
- +0 -13 [M] web/flaskapp.py
- Register
main_blueprint
anditem_blueprint
Blueprint objects with the application.
init_logging(app)
+ from .main import main as main_blueprint
+ app.register_blueprint(main_blueprint)
+
+ from .item import item as item_blueprint
+ app.register_blueprint(item_blueprint)
+
return app
- Create
Blueprint
object for theitem
module. - The Blueprint is registered during the
app.create_app()
process.
+from flask import Blueprint
+
+item = Blueprint('item', __name__, template_folder='templates')
+
+from . import views
- Create initial route
/item/
to test module.
+import logging
+
+from flask import current_app, escape
+from . import item
+
+
+@item.route('/item/')
+def hello_item():
+ logging.info("hello_item()")
+ return 'Hello FlaskApp : Item Module'
- Create
Blueprint
object for themain
module. - The Blueprint is registered during the
app.create_app()
process.
+from flask import Blueprint
+
+main = Blueprint('main', __name__, template_folder='templates')
+
+from . import views
- Create initial route
/main/
to test module. - Relocate routes
/info/date
and/info/config
fromflaskapp.py
- Add route
/info/url_map
.
+import datetime
+import logging
+import os
+
+from flask import current_app, escape
+from . import main
+
+
+@main.route('/main/')
+def hello_main():
+ logging.info("hello_main()")
+ return 'Hello FlaskApp : Main Module'
+
+
+@main.route('/info/date')
+def info_date():
+ ts = datetime.datetime.now().strftime("%Y/%m/%d @ %H:%M:%S")
+ return "Current Datetime : %s" % ts
+
+
+@main.route('/info/config')
+def info_config():
+ cnf = dict(current_app.config)
+ return "'%s' Config : %s" % (os.getenv('FLASK_CONFIG'),cnf)
+
+
+@main.route('/info/url_map')
+def info_url_map():
+ return "current_app.url_map:<pre> %s </pre>" % escape(current_app.url_map)
- Relocate routes
/info/date
and/info/config
tomain
module.
-
-@app.route('/info/date')
-def info_date():
- ts = datetime.datetime.now().strftime("%Y/%m/%d @ %H:%M:%S")
- return "Current Datetime : %s" % ts
-
-
-@app.route('/info/config')
-def app_config():
- cnf = dict(app.config)
- return "'%s' Config : %s" % (os.getenv('FLASK_CONFIG'),cnf)
-
Commit-v0.6 | Commit-v0.7 | Commit-v0.8
- FlaskApp Tutorial
- Table of Contents
- About
- Application Setup
- Modules, Templates, and Layouts
- Database Items, Forms, and CRUD
- List Filter, Sort, and Paginate
- Users and Login
- Database Relationships
- API Module, HTTPAuth and JSON
- Refactoring User Roles and Item Status
- AJAX and Public Pages