Closed darrenvong closed 6 years ago
Just finished writing up a rough plan for the next two sessions... It's ended up a lot longer than I expected :joy:
Tagged you in as well @paulienuh since you're the pro of the Beginner's course. Do all of these make sense/will this structure transition well for those who have done the course?
Also @cgmcintyr when you have recovered from HackNotts and have a moment, take a look! :)
Ignore the part in the curriculum note which says that we need to control-c and restart our server. It's wrong. With debug=True, Flask restarts the server automatically when it detects code changes.
It might be worth pointing out that this is the case and that the debug=True
enables live update of the app
Also
Show good practices like breaking down common HTML parts across all pages (headers/footers) of a typical website into separate template files?
I think this would be the best approach given the fact that most of them have not done the beginners course... IMO only, you're the boss here @darrenvong
Thanks for the feedback @trallard! I agree that the breaking down into parts pattern is probably the better route to go - the idea that this will then lead to re-usable bits seem more intuitive!
The base template then inherit style might be a bit confusing if not covered well, considering we won't really be doing anything Object Oriented related...
Just wanted to say that after seeing the slides, I really liked how you've laid this out @darrenvong! A huge improvement from last year's for sure - I'll be sitting in and working through it myself too!
Hmm just gonna reopen this before session 4 is done so I can quickly find it :blush:
Still need to cover Sending data from HTML template back to Python part, otherwise we should be good to move forward...
So what is actually missing?
Did you cover the other way around from Python to the HTML template?
@trallard Yes, that was covered in session 3. The main things we haven't covered yet include:
It really should have been done and dusted in the last session, but sadly it went quite far off plan... π
Is all of the material for the missing bits in the repo now?
All the bits I've prepared are there, although I think @cgmcintyr has some additional slides when he quickly gave an overview on HTTP requests towards the end of the last session.
I've also slipped in forms in this week's challenge (tough to set one when we practically did nothing...), so if the girls engage with it then they should have an awareness of it by next session.
Here's a rough structure of how I'm thinking the session and a half should go:
Beginning of Session 3 and 4
Session 3
Before we go into the technical details on how to use Flask, cover:
Now, the technical part:
Live code together the very first, basic Flask app
python app.py
command in the terminal (assuming we named our fileapp.py
)localhost:5000
and they should be able to see "Hello, #ShefCodeFirst students" in their browserlocalhost:5000/ihf
to show that it will lead to an error, since we haven't defined how to handle requests forihf
Follow up with an example which takes a URL parameter (similar to "arguments" mentioned in Python). E.g. a function with
@app.route("/<name>")
above will capture "darren" in the variablename
iflocalhost:5000/darren
is typed in the browserIgnore the part in the curriculum note which says that we need to control-c and restart our server. It's wrong. With
debug=True
, Flask restarts the server automatically when it detects code changes.Set up a typical Flask app folder structure together
static
folder where CSS, JavaScript and other resources (images, videos) are placedtemplates
folder, where the HTML files goLinking up a basic HTML template together
render_template
functionrender_template
function from Python in the templatesSession 4
Picking up from where we left off from the previous session, before we dive into the technical details:
What is a template engine? Why do we use it?
Routing?
/hello
therefore can be accessed by<hostname>:<port_number>/hello
POST requests
Now, the technical details:
request
fromFlask
!request.value
convenienceCombinedMultiDict
from Flask to grab data from requests to ease confusion!{% include "header.html" %}
etc to load it into main page HTML templateAlternatively, seems to be recommended by the official Jinja2 guide, have a "base" template which basically contains the common bits (headers, footers etc) with blocks that can be replaced by page specific templates?