Skip to content

Commit v0.8

kwmccabe edited this page Apr 17, 2018 · 8 revisions

v0.8 - render_template("hello.html", message=message)


Files changed (3)

File web/app/main/views.py MODIFIED

  • 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)

File web/app/templates/hello.html ADDED

  • Create a minimal Jinja2 template.
  • Display page_title value passed in render_template('hello.html', page_title=title).
+<h1>{{ page_title }}</h1>
+<p>template = hello.html</p>

File web/flaskapp.py MODIFIED

  • Replace return 'Hello FlaskApp'.
  • Call Flask's render_template() method to generate the page output.
  • Pass the value page_title to the template file templates/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

Clone this wiki locally