In production, you don't want to serve static files using the flask server. I suggest you use a proper web server to do that.

For dev, since you don't want to use url_for, you can try to initialize your flask app as below. This way, flask knows where your static files are.

app = Flask(__name__, static_folder='static')  

@app.route('/<path:filename>')  
def send_file(filename):  
    return send_from_directory(app.static_folder, filename)

See this post with a lot of info Static files in Flask - robot.txt, sitemap.xml (mod_wsgi)

Answer from codegeek on Stack Overflow
๐ŸŒ
Flask
flask.palletsprojects.com โ€บ en โ€บ stable โ€บ api
API โ€” Flask Documentation (3.1.x)
The Click command group for registering CLI commands for this object. The commands are available from the flask command once the application has been discovered and blueprints have been registered. ... Used by send_file() to determine the max_age cache value for a given file path if it wasnโ€™t ...
๐ŸŒ
Beautiful Soup
tedboy.github.io โ€บ flask โ€บ generated โ€บ flask.send_from_directory.html
flask.send_from_directory โ€” Flask API
flask.send_from_directory ยท View page source ยท flask.send_from_directory(directory, filename, **options)[source]ยถ ยท Send a file from a given directory with send_file(). This is a secure way to quickly expose static files from an upload folder or something similar.
Discussions

send_from_directory is ignoring the path value being supplied
I am trying to use send_from_directory with RESTPlus and it looks as thought it is ignoring the path I am giving it in the first argument (code greatly simplified down to basics): @api.route('/... More on github.com
๐ŸŒ github.com
2
December 13, 2019
Using send_file on an entire directory
Perhaps I'm mistaken, but I don't think there's a web/browser concept of downloading a directory. You need to ZIP up the directory then serve the ZIP file. More on reddit.com
๐ŸŒ r/flask
2
8
December 24, 2021
Save and display static file with flask : Forums : PythonAnywhere
I fixed my problem by changing my working directory from this ... Home โ”œโ”€โ”€โ”€mysite โ””โ”€โ”€โ”€ templates โ”‚ โ””โ”€โ”€โ”€ index.html โ””โ”€โ”€โ”€ static โ”‚ โ””โ”€โ”€โ”€images โ””โ”€โ”€โ”€ server.py (flask app) More on pythonanywhere.com
๐ŸŒ pythonanywhere.com
August 9, 2023
Problem retreiving uploaded files with send_from_directory
Hey...try removing 'myapp' from the UPLOAD_FOLDER variable More on reddit.com
๐ŸŒ r/flask
6
3
October 5, 2020
๐ŸŒ
GitHub
github.com โ€บ noirbizarre โ€บ flask-restplus โ€บ issues โ€บ 761
send_from_directory is ignoring the path value being supplied ยท Issue #761 ยท noirbizarre/flask-restplus
December 13, 2019 - @api.route('/missions/<path:file_name>') @api.param('file_name', 'The file to download') class MissionFile(Resource): def get(self, file_name): return send_from_directory('./data', file_name, as_attachment=True)
Author ย  noirbizarre
๐ŸŒ
Reddit
reddit.com โ€บ r/flask โ€บ using send_file on an entire directory
r/flask on Reddit: Using send_file on an entire directory
December 24, 2021 -

Hello! I'm wondering if it is possible to let the user download a directory/folder using send_file. When I try to pass in a directory instead of a file to send_file, I get a permission error in Visual Studio Code.

Edit: Solved! Here's how I did it in case anyone ever has this issue.

If you make the folder into a zip file (using shutil.make_archive for example) then you can pass in the zip file to flask.send_file() and it'll work.

Thank you u/weebsnore for your help!

๐ŸŒ
Medium
medium.com โ€บ @01one โ€บ create-the-simplest-static-file-download-server-with-python-flask-bd6ea3950a56
Create the simplest static file download server with python flask | by Mashiur Rahman | Medium
September 10, 2025 - project-directory/ โ”‚ โ”œโ”€โ”€ app.py โ””โ”€โ”€ static/ โ””โ”€โ”€ image.jpg ... # app.py from flask import Flask, send_from_directory app = Flask(__name__) @app.route('/<filename>') def download_file(filename): # The directory where the files are located directory = 'static' # Flask's send_from_directory to send the file to the client return send_from_directory(directory, filename, as_attachment=True) if __name__ == '__main__': app.run(host='0.0.0.0', port=5000, debug=True)
Find elsewhere
๐ŸŒ
Workroom Productions
workroom-productions.com โ€บ serving-a-directory-with-flask
Publishing a Directory with Flask
October 18, 2022 - __name__, ) ## Routing โ€“ so when a browser asks for a resource, it gets something from the app @app.route('/') # empty route should serve ./cov_html/index.html def index(): return send_from_directory('./cov_html/', 'index.html') @app.route('/<path:path>') #Everything else just goes by filename def sendstuff(path): print(path) return send_from_directory('./cov_html/', path) ## Boilerplate to start server if __name__ == "__main__": # Makes sure this is the main process app.run( # Starts the site host='0.0.0.0', # Establishes the host, required for repl to detect the site port=8080 # port to serve )
๐ŸŒ
PythonAnywhere
pythonanywhere.com โ€บ forums โ€บ topic โ€บ 33397
Save and display static file with flask : Forums : PythonAnywhere
August 9, 2023 - Here is my Flask apps route that is responsible for saving the image ยท @app.route('/vid', methods=['POST']) def receive_frame(): try: frame_data = request.data # Save the received frame as an image with open('static/images/received_frame.jpg', 'wb') as f: f.write(frame_data) return "Frame received and saved" except Exception as e: return f"Error: {e}" @app.route('/static/images/<filename>') def serve_image(filename): return send_from_directory('static/images', filename)
๐ŸŒ
Reddit
reddit.com โ€บ r/flask โ€บ problem retreiving uploaded files with send_from_directory
r/flask on Reddit: Problem retreiving uploaded files with send_from_directory
October 5, 2020 -

Hi everyone,

For a project, I architectured my Flask app as a package. So at the root, I'm having a config.py
file where I declare the uploads folder like this:

UPLOAD_FOLDER = 'myapp/uploads'

Now from myapp/routes.py, I manage to upload files in the right folder when creating a post, but then I try to declare a route to retrieve these files with:

@app.route('/uploads/')  

def upload(filename): return send_from_directory(app.config['UPLOAD_FOLDER'], filename)

But when displaying the html page where I call url_for('upload', filename=post.picture) I get a 404 on the image... like if Flask was trying to access /myapp/uploads from /myapp

Does someone have an idea?

I tried to hardcode "uploads" into the first parameter of send_from_directory with success. like this:

@app.route('/uploads/<filename>')
def upload(filename):
    return send_from_directory('uploads', filename)

But it's dirty and will break if I ever change the UPLOAD_FOLDER value in config.py. So I'm looking for a clean solution to this.

๐ŸŒ
GitHub
github.com โ€บ orgs โ€บ pallets โ€บ discussions โ€บ 4707
how to get request.files attribute after flask send_from_directory? ยท pallets ยท Discussion #4707
I have a master/slave architecture with master and slave flask restful apps and I want to send file from slave node to master node to send it further to user (different node). I used send_from_directory function to do it, but after applying that function on slave node, the request on master node doesnโ€™t have files attribute, so can neither push it forward to user node nor save it in tmp folder and send it to user from file system with send_from_directory.
๐ŸŒ
Flask
flask.palletsprojects.com โ€บ en โ€บ stable โ€บ patterns โ€บ fileuploads
Uploading Files โ€” Flask Documentation (3.1.x)
from flask import send_from_directory @app.route('/uploads/<name>') def download_file(name): return send_from_directory(app.config["UPLOAD_FOLDER"], name) If youโ€™re using middleware or the HTTP server to serve files, you can register the download_file endpoint as build_only so url_for will work without a view function.
๐ŸŒ
Codemia
codemia.io โ€บ knowledge-hub โ€บ path โ€บ how_to_serve_static_files_in_flask
How to serve static files in Flask
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises
๐ŸŒ
Python Programming
pythonprogramming.net โ€บ flask-send-file-tutorial
Return Files with Flask send_file Tutorial
@app.route('/return-files/') def return_files_tut(): try: return send_file('/var/www/PythonProgramming/PythonProgramming/static/images/python.jpg', attachment_filename='python.jpg') except Exception as e: return str(e)
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ uploading-and-downloading-files-in-flask
Uploading and Downloading Files in Flask - GeeksforGeeks
July 23, 2025 - In the app.py file we will write our main part of the code through these all operations will operate easily first in app.py we need to import all important libraries which are important for doing upload and returning files with database operations first we import io BytesIO this module will convert our all pdf files binary in below you can see what type of output will show in the database when we upload any pdf in the database and we import render_template for rendering templates and after that, we are importing send_file module which will help us to send the file to database and after that, we are importing flask_sqlalchemy for our SQL data ... from io import BytesIO from flask import Flask, render_template, request, send_file from flask_sqlalchemy import SQLAlchemy
๐ŸŒ
Python Forum
python-forum.io โ€บ thread-32178.html
Flask, send_from_directory not working : solved
January 26, 2021 - Hi everyone, here my simple test code : def download(): try: return send_from_directory('C:\\original.jpg', filename='original.jpg', as_attachment=True) except FileNotFoundError: abort(404)No matter w
๐ŸŒ
Ping SMS
ozeki-sms-gateway.com โ€บ p_865-python-flask-send-multiple-sms-with-the-http-rest-api-code-sample.html
Python flask send multiple sms with the HTTP rest api (code sample)
The Python sms code sample below demonstrates how you can send SMS using the http rest sms api of Ozeki SMS Gateway using the Python ozekilibsrest library. This library is provided to you free of charge, and you may use it and modify it in any of your projects. ... from flask import Flask, render_template, request from ozekilibsrest import Configuration, Message, MessageApi app = Flask(__name__) configuration = Configuration( username="http_user", password="qwe123", api_url="http://127.0.0.1:9509/api" ) api = MessageApi(configuration) messages_to_send = [] logs = [] @app.route('/', methods=['G
๐ŸŒ
Pythonpat
pythonpat.com โ€บ article โ€บ designing-a-user-interface-for-your-flask-app-a-star-wars-journey
Designing a User Interface for Your Flask App - Python Pat
Python Pat - A world to learn Python Flask and other cool stuff. Join Python Pat and discover how to create amazing web applications with Flask, the lightweight and powerful web framework for Python. Learn from tutorials, examples, and projects, and become a Flask master.
๐ŸŒ
Simon Jakowicz
jakowicz.com โ€บ flask-apache-wsgi
Running a Flask application under the Apache WSGI module | Simon Jakowicz
Double check you have a file called my.webtool inside the /etc/apache2/sites-available directory. You may have accidentally put the file inside /etc/apache2/sites-enabled. That would have the same effect as running the a2ensite command. I hope that helps. ... Hey so is this process only for a production server then? Im starting developing locally on mac osx and using pyvenv (python3.5). In the venv I have pip(by default), flask, and mod_wsgi installed. I have macs apache2 set up to serve from the ~/user/Sites directory, and mysql installed.