0
0
Flaskframework~10 mins

Serving images 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'
Arequest
Brender_template
Csend_file
Dredirect
Attempts:
3 left
💡 Hint
Common Mistakes
Using render_template instead of send_file
Forgetting to import send_file
2fill in blank
medium

Complete the code to create a Flask route that serves an image file named 'photo.jpg'.

Flask
@app.route('/image')
def serve_image():
    return [1]('photo.jpg')
Drag options to blanks, or click blank then click option'
Asend_file
Bredirect
Curl_for
Drender_template
Attempts:
3 left
💡 Hint
Common Mistakes
Using render_template instead of send_file
Using url_for which only generates URLs
3fill in blank
hard

Fix the error in the code to correctly serve an image with the right MIME type.

Flask
return send_file('photo.jpg', mimetype=[1])
Drag options to blanks, or click blank then click option'
A'image/jpeg'
B'text/html'
C'application/json'
D'audio/mpeg'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'text/html' which is for web pages
Using 'application/json' which is for JSON data
4fill in blank
hard

Fill both blanks to serve an image file from a folder named 'static/images'.

Flask
return send_file('[1]/[2]')
Drag options to blanks, or click blank then click option'
Astatic
Bimages
Ctemplates
Duploads
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'templates' folder which is for HTML files
Using 'uploads' which is not the folder here
5fill in blank
hard

Fill all three blanks to serve an image file named 'logo.png' with the correct MIME type from 'static/assets'.

Flask
return send_file('[1]/[2]/logo.png', mimetype=[3])
Drag options to blanks, or click blank then click option'
Astatic
Bassets
C'image/png'
D'image/jpeg'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'image/jpeg' MIME type for a PNG file
Mixing up folder names