0
0
Flaskframework~10 mins

Static folder configuration 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 create a Flask app with the default static folder.

Flask
from flask import Flask
app = Flask(__name__, static_folder=[1])

@app.route('/')
def home():
    return 'Hello, Flask!'

if __name__ == '__main__':
    app.run()
Drag options to blanks, or click blank then click option'
A'files'
B'assets'
C'public'
D'static'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a folder name other than 'static' without configuring Flask accordingly.
Leaving the static_folder parameter empty or None.
2fill in blank
medium

Complete the code to set a custom static folder named 'assets' in the Flask app.

Flask
from flask import Flask
app = Flask(__name__, static_folder=[1])

@app.route('/')
def home():
    return 'Welcome!'

if __name__ == '__main__':
    app.run()
Drag options to blanks, or click blank then click option'
A'static'
B'assets'
C'public'
D'resources'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to set static_folder when using a custom folder.
Using the wrong folder name string.
3fill in blank
hard

Fix the error in the code by completing the static_url_path parameter to serve static files from '/content'.

Flask
from flask import Flask
app = Flask(__name__, static_folder='static', static_url_path=[1])

@app.route('/')
def home():
    return 'Static files served from /content'

if __name__ == '__main__':
    app.run()
Drag options to blanks, or click blank then click option'
A'static/content'
B'/static'
C'/content'
D'content'
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the leading slash in the URL path.
Setting static_url_path to the folder name without a slash.
4fill in blank
hard

Fill both blanks to create a Flask app with a custom static folder 'assets' and serve static files from URL path '/resources'.

Flask
from flask import Flask
app = Flask(__name__, static_folder=[1], static_url_path=[2])

@app.route('/')
def home():
    return 'Custom static folder and URL path'

if __name__ == '__main__':
    app.run()
Drag options to blanks, or click blank then click option'
A'assets'
B'static'
C'/resources'
D'/assets'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up folder name and URL path values.
Forgetting the leading slash in the URL path.
5fill in blank
hard

Fill all three blanks to create a Flask app with static folder 'public', serve static files from '/staticfiles', and set static_host to None.

Flask
from flask import Flask
app = Flask(__name__, static_folder=[1], static_url_path=[2], static_host=[3])

@app.route('/')
def home():
    return 'Static files with custom folder, path and host'

if __name__ == '__main__':
    app.run()
Drag options to blanks, or click blank then click option'
A'public'
B'/staticfiles'
CNone
D'/public'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect folder or URL path names.
Setting static_host to a string instead of None.