mirror of
https://github.com/fastapi-admin/fastapi-admin.git
synced 2025-08-14 18:58:13 +08:00
chore: update deps and example
This commit is contained in:
@ -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,
|
||||
|
Reference in New Issue
Block a user