chore: update deps and example

This commit is contained in:
long2ice
2024-05-20 15:23:57 +08:00
parent 08501d1e1f
commit e4a4cd511b
2 changed files with 758 additions and 678 deletions

View File

@ -27,8 +27,29 @@ from fastapi_admin.exceptions import (
)
@asynccontextmanager
async def lifespan(app: FastAPI):
r = redis.from_url(
settings.REDIS_URL,
decode_responses=True,
encoding="utf8",
)
await admin_app.configure(
logo_url="https://preview.tabler.io/static/logo-white.svg",
template_folders=[os.path.join(BASE_DIR, "templates")],
favicon_url="https://raw.githubusercontent.com/fastapi-admin/fastapi-admin/dev/images/favicon.png",
providers=[
LoginProvider(
login_logo_url="https://preview.tabler.io/static/logo.svg",
admin_model=Admin,
)
],
redis=r,
)
def create_app():
app = FastAPI()
app = FastAPI(lifespan=lifespan)
app.mount(
"/static",
StaticFiles(directory=os.path.join(BASE_DIR, "static")),
@ -39,31 +60,13 @@ def create_app():
async def index():
return RedirectResponse(url="/admin")
admin_app.add_exception_handler(HTTP_500_INTERNAL_SERVER_ERROR, server_error_exception)
admin_app.add_exception_handler(
HTTP_500_INTERNAL_SERVER_ERROR, server_error_exception
)
admin_app.add_exception_handler(HTTP_404_NOT_FOUND, not_found_error_exception)
admin_app.add_exception_handler(HTTP_403_FORBIDDEN, forbidden_error_exception)
admin_app.add_exception_handler(HTTP_401_UNAUTHORIZED, unauthorized_error_exception)
@app.on_event("startup")
async def startup():
r = redis.from_url(
settings.REDIS_URL,
decode_responses=True,
encoding="utf8",
)
await admin_app.configure(
logo_url="https://preview.tabler.io/static/logo-white.svg",
template_folders=[os.path.join(BASE_DIR, "templates")],
favicon_url="https://raw.githubusercontent.com/fastapi-admin/fastapi-admin/dev/images/favicon.png",
providers=[
LoginProvider(
login_logo_url="https://preview.tabler.io/static/logo.svg",
admin_model=Admin,
)
],
redis=r,
)
app.mount("/admin", admin_app)
app.add_middleware(
CORSMiddleware,