-
Notifications
You must be signed in to change notification settings - Fork 8
Commit v0.8
kwmccabe edited this page Apr 17, 2018
·
8 revisions
v0.8 - render_template("hello.html", message=message)
- +3 -3 [M] web/app/main/views.py
- +3 -0 [A] web/app/templates/hello.html
- +5 -2 [M] web/flaskapp.py
- Standardize info output.
@main.route('/info/date')
def info_date():
ts = datetime.datetime.now().strftime("%Y/%m/%d @ %H:%M:%S")
- return "Current Datetime : %s" % ts
+ return "Current Datetime :<pre> %s </pre>" % ts
@main.route('/info/config')
def info_config():
cnf = dict(current_app.config)
- return "'%s' Config : %s" % (os.getenv('FLASK_CONFIG'),cnf)
+ return "'%s' Config :<pre> %s </pre>" % (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)
+ return "current_app.url_map :<pre> %s </pre>" % escape(current_app.url_map)
- Create a minimal Jinja2 template.
- Display
page_title
value passed inrender_template('hello.html', page_title=title)
.
+<h1>{{ page_title }}</h1>
+<p>template = hello.html</p>
- Replace
return 'Hello FlaskApp'
. - Call Flask's
render_template()
method to generate the page output. - Pass the value
page_title
to the template filetemplates/hello.html
.
+from flask import render_template
...
@app.route('/')
def hello_flaskapp():
- logging.info("hello_flaskapp()")
- return 'Hello FlaskApp'
+ title = "Hello FlaskApp"
+ logging.info("hello_flaskapp() : %s" % title)
+ return render_template('hello.html', page_title=title)
Commit-v0.7 | Commit-v0.8 | Commit-v0.9
- 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