Preview

2 - More Flask, Creation of templates, HTML, CSS

 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.

  TRUE

  FALSE

 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?

  return render_template('home.html',reviews=reviews)

  The code above does not show passing the data to the html template

  app = Flask(__name__)

  return render_template('about.html')

 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?

  Ideally, in a folder called 'pages' which is what the flask documentation suggests.

  Ideally, in a folder called 'html' which clearly identifies what it holds.

  Ideally, directly in the root or parent directory.

  Ideally, in a templates folder that is created inside the root directory.

 5. Refer to the following HTML code. The code inside the curly braces is:



	Big Questions



Big Questions

Welcome to our home page. We are going to ask incredible hard questions and attempt to answer them!

{% for review in reviews %}

{{}}

Name:{{review.name}} on date:{{review.date_posted}}

Review comment: {{review.comment}},

{% endfor %}

Thanks for visiting

BQ

  HTML

  Jinja

  JavaScript

  Python

 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?

  {{html.title}}

  {{review.title}}

  {{title}}

  {{title.reviews}}

 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?
{% block content %}

	

About

We hope you like our reviews

This site is, well, you know - about reviewing laptops. It is created in flask

{% endblock content %}

  After {% block content %} include the line {{! Layout.html!}}

  The first line should have this line of code: {% Add layout.html %}

  The first line should have this line of code included: {% extends "layout.html" %}

  Replace {{% block content %}} with {% extends "layout.html" %}

 8. Having a base template (like a layout.html) is useful as it follows the DRY principle. DRY stands for:

  Do not REPEAT Yourself.

  Do REPEAT Yourself.

  Do not render yelps

  Do Render Yes

 9. Analyse the following code. Which section of code indicates the only part that will be different on each webpage?








	{% block content %}{% endblock %}
	

Thanks for visiting

BQ

  Everything inside the body tags

  {% block content %}{% endblock %}

  Everything inside the head tags

  Everything inside the style tags

 10. Refer to the code above. Where is the CSS contained?

  Inside the H1 tags only

  Inside the body tags

  There is no CSS in this code

  Inside the style tags