For 2021 - online Python 3 training - see ((here)).
Our plans were to retire in summer 2020 and see the world, but Coronavirus has lead us into a lot of lockdown programming in Python 3 and PHP 7. We can now offer tailored online training - small groups, real tutors - works really well for groups of 4 to 14 delegates. Anywhere in the world; course language English.
Please ask about private 'maintenance' training for Python 2, Tcl, Perl, PHP, Lua, etc. |
Flask - calling in the templating engine
In previous steps, we have set up flask [here] and done some routing [here]. Let's now define our view.
Our view is in HTML (and with style and lots of other stuff later) and the template will be produced by an HTML expert and graphic artist, and not by a programmer. It will be in a separate place (actally a folder called "templates" to start with, and will be called up by another method in flask which says "fill in this template":
@app.route("//")
def greeting(folder,word):
return render_template('person.html',surname=folder.capitalize(),
forename=word.capitalize())
render_template needs to be loaded, so the code will also include:
from flask import render_template
and you'll start seeing some controller code within the main file, as we use Python to manipulate teh incoming data prior to passing it across to the rendering engine. Complete application code [here] and it renders like this:
But of course that's not the full story. How did the text get placed and thr other text added? Where was the format defined? That was all in the template - that file called person.html in the templates folder. You can find the source [here]. It includes:
<title>About {{forename}} {{surname}}</title>
and
<h1>All (or some) about {{forename}} {{surname}}</h1>
which are our place holders and our first use of the Jinja2 templating system. (written 2015-10-11)
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles Y307 - The Flask micro webdevelopment framework for Python [4527] Hello Flask world / Python web micro framework - (2015-10-11) [4528] Routing in Flask - (2015-10-11) [4530] Requests in Flask - (2015-10-11) [4531] Jinja2 - Flask templating - (2015-10-11) [4532] Flask - first forms and responses with wtforms - (2015-10-12) [4533] Sessions in flask - (2015-10-13) [4534] Flask - complete MVC site to navigate around a data set - (2015-10-13) [4538] Flask and unittest - hello web app test world - (2015-10-15) [4540] Unittest of a Flask application including forms - (2015-10-15)
Some other Articles
Flask - calling in the templating engineDay trip to LancasterWhat does Tcl do if you try to run a command that is not defined?Tcl - a new example for data reformatting
|
4759 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96 at 50 posts per page
This is a page archived from The Horse's Mouth at
http://www.wellho.net/horse/ -
the diary and writings of Graham Ellis.
Every attempt was made to provide current information at the time the
page was written, but things do move forward in our business - new software
releases, price changes, new techniques. Please check back via
our main site for current courses,
prices, versions, etc - any mention of a price in "The Horse's Mouth"
cannot be taken as an offer to supply at that price.
Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).
|
|