The download_name parameter sets the filename the browser suggests when saving the file.
Step 2: Analyze given code
The code sets download_name='user_data.csv', so the browser will suggest this name.
Final Answer:
user_data.csv -> Option B
Quick Check:
download_name sets saved filename [OK]
Hint: download_name sets the saved filename for downloads [OK]
Common Mistakes:
Assuming original filename is always used
Confusing download_name with as_attachment
Thinking no filename is suggested
4. Identify the error in this Flask code snippet intended to send a file for download:
return send_file('image.png', attachment=True)
medium
A. The parameter should be as_attachment=True, not attachment=True.
B. The filename must be absolute path, not relative.
C. send_file cannot send image files.
D. Missing download_name parameter.
Solution
Step 1: Check parameter correctness
The correct parameter to force download is as_attachment=True, not attachment=True.
Step 2: Validate other options
Relative paths are allowed, images can be sent, and download_name is optional.
Final Answer:
The parameter should be as_attachment=True, not attachment=True. -> Option A
Quick Check:
Correct parameter is as_attachment=True [OK]
Hint: Use as_attachment=True, not attachment=True [OK]
Common Mistakes:
Using attachment=True instead of as_attachment=True
Thinking download_name is mandatory
Believing relative paths are invalid
5. You want to send a PDF file named 'manual.pdf' for download but want the user to save it as 'User_Manual_2024.pdf'. Which Flask code snippet correctly achieves this?
hard
A. return send_file('manual.pdf', as_attachment=True, filename='User_Manual_2024.pdf')
B. return send_file('manual.pdf', as_attachment=False, download_name='User_Manual_2024.pdf')
C. return send_file('manual.pdf', download_name='User_Manual_2024.pdf')
D. return send_file('manual.pdf', as_attachment=True, download_name='User_Manual_2024.pdf')
Solution
Step 1: Ensure file is sent as download
Set as_attachment=True to force download instead of display.
Step 2: Set the saved filename
Use download_name='User_Manual_2024.pdf' to specify the filename suggested to the user.
Step 3: Check other options
return send_file('manual.pdf', as_attachment=False, download_name='User_Manual_2024.pdf') disables download, C misses as_attachment, D uses wrong parameter filename.
Final Answer:
return send_file('manual.pdf', as_attachment=True, download_name='User_Manual_2024.pdf') -> Option D
Quick Check:
Use as_attachment=True and download_name for filename [OK]
Hint: Use as_attachment=True and download_name to rename download [OK]
Common Mistakes:
Forgetting as_attachment=True disables download
Using filename instead of download_name
Setting as_attachment=False causes inline display
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.