0
0
Flaskframework~10 mins

File download responses 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 used to send files in Flask.

Flask
from flask import Flask, [1]
Drag options to blanks, or click blank then click option'
Asend_file
Brender_template
Crequest
Dredirect
Attempts:
3 left
💡 Hint
Common Mistakes
Importing unrelated functions like render_template or redirect.
Forgetting to import send_file.
2fill in blank
medium

Complete the code to send a file named 'report.pdf' from the 'files' folder.

Flask
return send_file('files/[1]')
Drag options to blanks, or click blank then click option'
Aimage.png
Bdocument.txt
Cdata.csv
Dreport.pdf
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong file name or extension.
Forgetting the folder path.
3fill in blank
hard

Fix the error in the code to set the file download name to 'summary.txt'.

Flask
return send_file('files/summary.txt', as_attachment=[1], download_name='summary.txt')
Drag options to blanks, or click blank then click option'
AFalse
B'True'
CTrue
D'False'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing 'True' as a string instead of boolean True.
Using False which disables download.
4fill in blank
hard

Fill both blanks to send a CSV file named 'data.csv' with the correct MIME type and force download.

Flask
return send_file('files/data.csv', mimetype=[1], as_attachment=[2])
Drag options to blanks, or click blank then click option'
A'text/csv'
BTrue
CFalse
D'application/json'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong MIME type like 'application/json'.
Setting as_attachment to False which shows file inline.
5fill in blank
hard

Fill all three blanks to send an image file 'photo.jpg' with correct MIME type, force download, and custom download name 'vacation.jpg'.

Flask
return send_file('files/photo.jpg', mimetype=[1], as_attachment=[2], download_name=[3])
Drag options to blanks, or click blank then click option'
A'image/jpeg'
BTrue
C'vacation.jpg'
DFalse
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong MIME type like 'image/png'.
Setting as_attachment to False which shows image inline.
Not setting download_name or using wrong file name.