1. Flask was originally designed and developed by Armin Ronacher as an April Fool's Day joke in 2010. Despite the origin as a joke, the Flask framework became wildly popular.
2. Analyse the following code. The home.html page will not be rendered. Why? Select the most likely answer.
from flask import Flask
app = Flask(__name__) #setting app variable to instance of flask class
#imagine that this is being stored in the database when a user makes a review
reviews=[
{
'title': 'What is meaning?',
'name': 'RM',
'comment': 'First ask, what is meaning?',
'date_posted': '12 June 2020'
},
{
'title': '42',
'name': 'JP',
'comment': 'Someone has to be stupid and say 42',
'date_posted': '13 August 2020'
}
]
@app.route('/') #this is what we type into our browser to go to pages. we create these using routes
@app.route('/home')
def home():
#we will now have access to this reviwes data in our template
return render_template('home.html',reviews=reviews)
@app.route('/about')
def about():
return render_template('about.html')
#this conditional will be true if we run this script and file with python directly
if __name__ == '__main__':
app.run(debug=True)
Line 1 at the top should be: from flask import Flask, render_template
Line 1 should also include the import: import HTML
The function that creates the route for home is incorrect. It should be: def home.html():
Line 2 shoud be: html=Flask(__name__)
3. Looking again at the code above, on what line are we passing the contents of the dummy data to the home.html template?
4. A flask project has a main python file and two html pages called home.html and about.html. Where are the html pages stored?
5. Refer to the following HTML code. The code inside the curly braces is:
6. In the code above, the h1 tag should display the title of each review. What should go in the curly brackets between the h1 tags?
7. You have this code in the about.html page. You want it to display the header and footer that are created in the page called layout.html. What needs adding?
8. Having a base template (like a layout.html) is useful as it follows the DRY principle. DRY stands for:
9. Analyse the following code. Which section of code indicates the only part that will be different on each webpage?
10. Refer to the code above. Where is the CSS contained?