Не видит папку static в APIRouter FastAPI
В проекте FastAPI создал подпапку admin_jinja для APIRouter
project
├── admin
│ ├── admin_router.py
│
├── admin_jinja
│ ├── admin_jinja.py
│ │
│ ├── static
│ └── templates
│ └── index.html
├── main.py
admin_jinja.py
from fastapi import APIRouter, Request
from fastapi.responses import HTMLResponse
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
admin_jinja = APIRouter()
admin_jinja.mount("/static", StaticFiles(directory="admin_jinja/static"), name="static")
templates = Jinja2Templates(directory="admin_jinja/templates")
@admin_jinja.get("/", response_class=HTMLResponse)
async def index(request: Request):
return templates.TemplateResponse("index.html", {"request": request})
index.html
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{% block title %} {% endblock%}</title>
<link rel="stylesheet" href="{{ url_for('/static', path='css/style.css') }}">
</head>
Проблема именно в url_for()
<link rel="stylesheet" href="{{ url_for('/static', path='css/style.css') }}">
Ошибка: starlette.routing.NoMatchFound: No route exists for name "/static" and params "path".