Home / Function/ send_from_directory() — flask Function Reference

send_from_directory() — flask Function Reference

Architecture documentation for the send_from_directory() function in helpers.py from the flask codebase.

Entity Profile

Dependency Diagram

graph TD
  cd968d21_9286_02d4_74b3_ae5e22f8a986["send_from_directory()"]
  881f9803_28d6_7d77_c8d7_1098b41ccf84["helpers.py"]
  cd968d21_9286_02d4_74b3_ae5e22f8a986 -->|defined in| 881f9803_28d6_7d77_c8d7_1098b41ccf84
  0961f519_f2ef_dd1b_2adf_c3eaabdb53a7["send_static_file()"]
  0961f519_f2ef_dd1b_2adf_c3eaabdb53a7 -->|calls| cd968d21_9286_02d4_74b3_ae5e22f8a986
  4a852f3a_2bc8_50e9_493b_6ec8169d1a41["send_static_file()"]
  4a852f3a_2bc8_50e9_493b_6ec8169d1a41 -->|calls| cd968d21_9286_02d4_74b3_ae5e22f8a986
  04d28ef5_1747_490a_b80c_227d53a1ec17["_prepare_send_file_kwargs()"]
  cd968d21_9286_02d4_74b3_ae5e22f8a986 -->|calls| 04d28ef5_1747_490a_b80c_227d53a1ec17
  style cd968d21_9286_02d4_74b3_ae5e22f8a986 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/flask/helpers.py lines 530–571

def send_from_directory(
    directory: os.PathLike[str] | str,
    path: os.PathLike[str] | str,
    **kwargs: t.Any,
) -> Response:
    """Send a file from within a directory using :func:`send_file`.

    .. code-block:: python

        @app.route("/uploads/<path:name>")
        def download_file(name):
            return send_from_directory(
                app.config['UPLOAD_FOLDER'], name, as_attachment=True
            )

    This is a secure way to serve files from a folder, such as static
    files or uploads. Uses :func:`~werkzeug.security.safe_join` to
    ensure the path coming from the client is not maliciously crafted to
    point outside the specified directory.

    If the final path does not point to an existing regular file,
    raises a 404 :exc:`~werkzeug.exceptions.NotFound` error.

    :param directory: The directory that ``path`` must be located under,
        relative to the current application's root path. This *must not*
        be a value provided by the client, otherwise it becomes insecure.
    :param path: The path to the file to send, relative to
        ``directory``.
    :param kwargs: Arguments to pass to :func:`send_file`.

    .. versionchanged:: 2.0
        ``path`` replaces the ``filename`` parameter.

    .. versionadded:: 2.0
        Moved the implementation to Werkzeug. This is now a wrapper to
        pass some Flask-specific arguments.

    .. versionadded:: 0.5
    """
    return werkzeug.utils.send_from_directory(  # type: ignore[return-value]
        directory, path, **_prepare_send_file_kwargs(**kwargs)
    )

Subdomains

Frequently Asked Questions

What does send_from_directory() do?
send_from_directory() is a function in the flask codebase, defined in src/flask/helpers.py.
Where is send_from_directory() defined?
send_from_directory() is defined in src/flask/helpers.py at line 530.
What does send_from_directory() call?
send_from_directory() calls 1 function(s): _prepare_send_file_kwargs.
What calls send_from_directory()?
send_from_directory() is called by 2 function(s): send_static_file, send_static_file.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free