Skip to content

Обслуживание статических файлов

Эти настройки используются для управления обслуживанием статических файлов сервером.

Bases: BaseModel

Static files serving settings.

Files are served at /static endpoint.

Examples

.. code-block:: bash

DATA_RENTGEN__SERVER__STATIC_FILES__ENABLED=True
DATA_RENTGEN__SERVER__STATIC_FILES__DIRECTORY=/app/data_rentgen/server/static
Source code in data_rentgen/server/settings/static_files.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
class StaticFilesSettings(BaseModel):
    """Static files serving settings.

    Files are served at ``/static`` endpoint.

    Examples
    --------

    .. code-block:: bash

        DATA_RENTGEN__SERVER__STATIC_FILES__ENABLED=True
        DATA_RENTGEN__SERVER__STATIC_FILES__DIRECTORY=/app/data_rentgen/server/static
    """

    enabled: bool = Field(default=True, description="Set to ``True`` to enable static file serving")
    directory: Path = Field(
        default=Path("docs/_static"),
        description="Directory containing static files",
    )

    @field_validator("directory")
    def _validate_directory(cls, value: Path) -> Path:  # noqa: N805
        if not value.exists():
            msg = f"Directory '{value}' does not exist"
            raise ValueError(msg)
        if not value.is_dir():
            msg = f"Path '{value}' is not a directory"
            raise ValueError(msg)
        return value