Differences

This shows you the differences between two versions of the page.

Link to this comparison view

ii:labs:s2:02:tasks:03 [2024/03/17 15:45]
florin.stancu removed
ii:labs:s2:02:tasks:03 [2024/03/17 18:24] (current)
florin.stancu
Line 1: Line 1:
-==== 03. [30p] Mock Authentication ​====+==== 03. [30p] Firing up the Flask backend ​====
  
-Now it'​s ​the time to add authentication to our website.+First, let'​s ​understand how Flask serves files:
  
-  * You can use simple server-side global variable ​(e.g., ''​session''​) to store the user's state (e.g.an ''​authenticated''​ boolean + ''​username''​). +  * Download ​random photo from the Internet ​(e.g., ​your favorite snake species) and place it into ''​public/​myimage.jpg''​ (or use whatever name you wishbut keep this directory!); 
-  * Write the Flask functions for ''​login.html''​ and ''​logout.html'' ​with the appropriate checks / actions+  * Start up the Flask server (''​python3 server.py''​and point your browser to ''​http://​localhost:​5000/​public/​myimage.jpg''​, it should display your image
-  * Hint: also set the ''​authenticated'' ​variable inside ​the Jinja template ​to conditionally display the user's status.+  * Copy/rename or download another image directly to your project's root, alongside ​''​server.py''; start the web server, point your browser ​to ''​http://​localhost:​5000/​myimage2.jpg''​ -- it won't work..why?
  
-<​note>​ +Nowwe want to move the ''​html''​ page from earlier tasks to be served by the Flask web server:
-This is not really how it's done in practicesince the global variable will have the same value for all of the website's users (i.e., if one user authenticates,​ all other visitors will see the website in this state). +
-</​note>​+
  
 +  * Copy the ''​initial_design.html''​ to the ''​templates/''​ directory (we're using the default Flask convention);​
 +  * Modify ''​server.py''​ to call ''​render_template''​ ([[https://​flask.palletsprojects.com/​en/​3.0.x/​quickstart/#​rendering-templates|see official quickstart guide]]) and actually serve your HTML file.
 +  * Fire it up!
 +
 +<note important>​
 +Don't forget to import the ''​render_template''​ symbol from the Flask library!
 +</​note>​
  
 +  * Finally for this task, make a ''/​google''​ endpoint which automatically redirects to your favorite (or not) search engine!
ii/labs/s2/02/tasks/03.1710683159.txt.gz · Last modified: 2024/03/17 15:45 by florin.stancu
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0