forked from DucarrougeR/COMP30670_Final-Project-DublinBikes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Info_on_Flask.txt
25 lines (19 loc) · 1.29 KB
/
Info_on_Flask.txt
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
BASIC NOTES ON FLASK AND JINJA
- Using Flask to insert data into our webpage requires Jinja.
- Jinja allows us to insert data returned from a flask function directly into our html page
- For this to work, the html page that we wish to modify must be in a directory called "templates".
- This directory must be in the same directory as "app.py" (the python script in which we write our flask functions)
- In addition to "templates", we must also create a directory called "static".
- The "static" directory will contain all the javascript, css, and image files that the main html page references.
- For all sources in the html page, the format should be changed to the following:
src="{{url_for('static',filename='xyz')}}
- In the above, "xyz" should be replaced by the name of the file.
- "src" may also be "href", depending on the link that is used in the original html file
- This format allows the page to maintain access to these files while undergoing changes via Jinja
- Within our html page that is located in "templates", we can insert variables returned from flask functions as follows:
<body>
<div>
<p>The variable returned was: {{my_variable}}}</p>
</div>
</body>
- If we return a variable called "my_variable" from a flask function, it's value will be inserted in place of {{my_variable}}