quart.static module

class quart.static.PackageStatic(import_name: str, template_folder: Optional[str] = None, root_path: Optional[str] = None, static_folder: Optional[str] = None, static_url_path: Optional[str] = None)

Bases: object

get_send_file_max_age(filename: str) → int
property has_static_folder
property jinja_loader
open_resource(path: Union[bytes, str, os.PathLike], mode: str = 'rb') → IO

Open a file for reading.

Use as

with app.open_resource(path) as file_:
    file_.read()
async send_static_file(filename: str)quart.wrappers.response.Response
property static_folder
property static_url_path
quart.static.safe_join(directory: Union[bytes, str, os.PathLike], *paths: Union[bytes, str, os.PathLike]) → pathlib.Path

Safely join the paths to the known directory to return a full path.

Raises
  • NotFound – if the full path does not share a commonprefix with

  • the directory.

async quart.static.send_file(filename_or_io: Union[bytes, str, os.PathLike, _io.BytesIO], mimetype: Optional[str] = None, as_attachment: bool = False, attachment_filename: Optional[str] = None, add_etags: bool = True, cache_timeout: Optional[int] = None, conditional: bool = False, last_modified: Optional[datetime.datetime] = None)quart.wrappers.response.Response

Return a Response to send the filename given.

Parameters
  • filename_or_io – The filename (path) to send, remember to use safe_join().

  • mimetype – Mimetype to use, by default it will be guessed or revert to the DEFAULT_MIMETYPE.

  • as_attachment – If true use the attachment filename in a Content-Disposition attachment header.

  • attachment_filename – Name for the filename, if it differs

  • add_etags – Set etags based on the filename, size and modification time.

  • last_modified – Used to override the last modified value.

  • cache_timeout – Time in seconds for the response to be cached.

async quart.static.send_from_directory(directory: Union[bytes, str, os.PathLike], file_name: str, *, mimetype: Optional[str] = None, as_attachment: bool = False, attachment_filename: Optional[str] = None, add_etags: bool = True, cache_timeout: Optional[int] = None, conditional: bool = True, last_modified: Optional[datetime.datetime] = None)quart.wrappers.response.Response

Send a file from a given directory.

Parameters
  • directory – Directory that when combined with file_name gives the file path.

  • file_name – File name that when combined with directory gives the file path.

See send_file() for the other arguments.