Skip to content

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

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

Bases: BaseModel

Static files serving settings.

Files are served at /static endpoint.

Examples

.. code-block:: bash

HORIZON__SERVER__STATIC_FILES__ENABLED=True
HORIZON__SERVER__STATIC_FILES__DIRECTORY=/app/horizon/backend/static
Source code in horizon/backend/settings/server/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

        HORIZON__SERVER__STATIC_FILES__ENABLED=True
        HORIZON__SERVER__STATIC_FILES__DIRECTORY=/app/horizon/backend/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",
    )

    @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