0
0
Flaskframework~10 mins

Flash messages for user feedback 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 needed to show flash messages in Flask.

Flask
from flask import Flask, render_template, [1]
Drag options to blanks, or click blank then click option'
Asession
Burl_for
Cflash
Dredirect
Attempts:
3 left
💡 Hint
Common Mistakes
Importing 'redirect' instead of 'flash'.
Forgetting to import 'flash' at all.
2fill in blank
medium

Complete the code to flash a success message after a user logs in.

Flask
flash('Login successful!', category=[1])
Drag options to blanks, or click blank then click option'
A'success'
B'warning'
C'info'
D'error'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'error' category for success messages.
Omitting the category parameter.
3fill in blank
hard

Fix the error in the code to display flash messages in the template using Jinja2.

Flask
{% for message in get_flashed_messages(with_categories=[1]) %}
  <div class="alert alert-{{ message[0] }}">{{ message[1] }}</div>
{% endfor %}
Drag options to blanks, or click blank then click option'
ATrue
BFalse
CNone
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using False causes only messages without categories to be returned.
Using None or 0 does not return categories.
4fill in blank
hard

Fill both blanks to flash an error message and redirect to the login page.

Flask
flash('Invalid credentials', category=[1])
return [2](url_for('login'))
Drag options to blanks, or click blank then click option'
A'error'
Bredirect
Curl_for
D'success'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'success' category for error messages.
Using 'url_for' instead of 'redirect' for returning.
5fill in blank
hard

Fill all three blanks to flash a message, redirect, and generate the URL for the home page.

Flask
flash('Welcome back!', category=[1])
return [2]([3]('home'))
Drag options to blanks, or click blank then click option'
A'success'
Bredirect
Curl_for
D'info'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up redirect and url_for.
Using wrong category for the message.