0
0
Flaskframework~10 mins

HTML email templates 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 send an HTML email using Flask-Mail.

Flask
from flask_mail import Message
msg = Message(subject='Hello', recipients=['user@example.com'])
msg.[1] = '<h1>Welcome!</h1><p>This is an HTML email.</p>'
Drag options to blanks, or click blank then click option'
Acontent
Bbody
Ctext
Dhtml
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'body' instead of 'html' for HTML content.
Using 'text' which is for plain text emails.
2fill in blank
medium

Complete the code to render an HTML email template with Flask's render_template.

Flask
from flask import render_template
html_content = render_template('[1]', username='Alice')
Drag options to blanks, or click blank then click option'
Aemail_template.html
Bemail_template.txt
Cemail_template.py
Demail_template.css
Attempts:
3 left
💡 Hint
Common Mistakes
Using a text or CSS file instead of an HTML template.
Using a Python file as a template.
3fill in blank
hard

Fix the error in the code to send an HTML email with Flask-Mail.

Flask
msg = Message('Greetings', recipients=['test@example.com'])
msg.body = 'Hello!'
msg.[1] = '<p>This is an HTML email.</p>'
mail.send(msg)
Drag options to blanks, or click blank then click option'
Atext
Bmessage
Chtml
Dcontent
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'content' or 'text' instead of 'html'.
Trying to set 'message' attribute which does not exist.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps usernames to their email HTML content.

Flask
emails = {user: render_template([1], username=user) for user in users if user [2] 'admin'}
Drag options to blanks, or click blank then click option'
A'email_template.html'
B==
C!=
D'admin'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '!=' to exclude 'admin'.
Using a non-HTML template file.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension filtering users and rendering HTML emails.

Flask
emails = [1]: render_template('email_template.html', username=[2]) for [3] in users if [2] != 'guest'}}
Drag options to blanks, or click blank then click option'
Auser.upper()
Buser
Dusername
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'username' as loop variable which is undefined.
Not using uppercase for keys.