0
0
Flaskframework~10 mins

Render_template function in Flask - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the function that renders HTML templates in Flask.

Flask
from flask import [1]
Drag options to blanks, or click blank then click option'
Arender_template
Brequest
CFlask
Dredirect
Attempts:
3 left
💡 Hint
Common Mistakes
Importing 'Flask' instead of 'render_template'.
Using 'request' which is for handling data, not templates.
2fill in blank
medium

Complete the code to return the 'index.html' template from a Flask route.

Flask
@app.route('/')
def home():
    return [1]('index.html')
Drag options to blanks, or click blank then click option'
Aredirect
Burl_for
Crequest
Drender_template
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'redirect' which sends users to another URL.
Using 'request' which handles incoming data.
3fill in blank
hard

Fix the error in the code to correctly render 'about.html' with Flask.

Flask
@app.route('/about')
def about():
    return render_template([1])
Drag options to blanks, or click blank then click option'
A"about.html"
Babout.html
C'about.html'
Dabout
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the template name without quotes causes a NameError.
Using just the word 'about' without '.html' is incorrect.
4fill in blank
hard

Fill both blanks to pass a variable 'name' with value 'Alice' to the template.

Flask
return render_template('hello.html', [1]=[2])
Drag options to blanks, or click blank then click option'
Aname
B'Alice'
CAlice
Duser
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting the string value 'Alice'.
Using a different variable name than 'name'.
5fill in blank
hard

Fill all three blanks to render 'profile.html' passing the 'username' variable with value 'john_doe'.

Flask
return render_template('[1]', [2]=[3])
Drag options to blanks, or click blank then click option'
Aprofile.html
Busername
C'john_doe'
Dage
E30
Attempts:
3 left
💡 Hint
Common Mistakes
Passing variables without quotes for string values.
Mixing variable names or values.