Is that possible to add more static paths for my local dev Flask instance? I want to have default static
folder for storing js/css/images files for the site and another folder, e.g. designs
to keep my specific assets. I don't want to place designs
folder inside static
if there is a better solution exists.
To use static files in a Flask application, create a folder called static in your package or next to your module and it will be available at /static on the application. app.py is a basic example of Flask with template rendering.
Folder structure for a Flask app That folder contains two folders, specifically named static and templates. The static folder contains assets used by the templates, including CSS files, JavaScript files, and images.
Static files are files that don't change when your application is running. These files do a lot to improve your application, but they aren't dynamically generated by your Python web server. In a typical web application, your most common static files will be the following types: Cascading Style Sheets, CSS.
I have been using following approach:
# Custom static data @app.route('/cdn/<path:filename>') def custom_static(filename): return send_from_directory(app.config['CUSTOM_STATIC_PATH'], filename)
The CUSTOM_STATIC_PATH
variable is defined in my configuration.
And in templates:
{{ url_for('custom_static', filename='foo') }}
Caveat emptor - I'm not really sure whether it's secure ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With