Participer au site avec un Tip
Rechercher
 

Améliorations / Corrections

Vous avez des améliorations (ou des corrections) à proposer pour ce document : je vous remerçie par avance de m'en faire part, cela m'aide à améliorer le site.

Emplacement :

Description des améliorations :

Vous êtes un professionnel et vous avez besoin d'une formation ? Deep Learning avec Python
et Keras et Tensorflow
Voir le programme détaillé
Module « flask »

Fonction send_from_directory - module flask

Signature de la fonction send_from_directory

def send_from_directory(directory: 'os.PathLike[str] | str', path: 'os.PathLike[str] | str', **kwargs: 't.Any') -> 'Response' 

Description

help(flask.send_from_directory)

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


Vous êtes un professionnel et vous avez besoin d'une formation ? Deep Learning avec Python
et Keras et Tensorflow
Voir le programme détaillé