Complete the code to create a Flask app with the default static folder.
from flask import Flask app = Flask(__name__, static_folder=[1]) @app.route('/') def home(): return 'Hello, Flask!' if __name__ == '__main__': app.run()
The default static folder in Flask is named static. Setting static_folder='static' tells Flask where to find static files like CSS and images.
Complete the code to set a custom static folder named 'assets' in the Flask app.
from flask import Flask app = Flask(__name__, static_folder=[1]) @app.route('/') def home(): return 'Welcome!' if __name__ == '__main__': app.run()
To use a custom folder for static files, set static_folder to the folder name, here 'assets'.
Fix the error in the code by completing the static_url_path parameter to serve static files from '/content'.
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()
The static_url_path sets the URL path to access static files. To serve them from '/content', set static_url_path='/content'.
Fill both blanks to create a Flask app with a custom static folder 'assets' and serve static files from URL path '/resources'.
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()
Set static_folder='assets' to specify the folder name, and static_url_path='/resources' to set the URL path for static files.
Fill all three blanks to create a Flask app with static folder 'public', serve static files from '/staticfiles', and set static_host to None.
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()
Set static_folder='public' for the folder name, static_url_path='/staticfiles' for the URL path, and static_host=None to serve static files from the app's host.