constraints¶
- class litestar.middleware.constraints.MiddlewareConstraints[源代码]¶
基类:
objectConstraints for a middleware.
- before: tuple[MiddlewareForwardRef | Middleware | MiddlewareFactory, ...] = ()¶
Tuple of middlewares that, if present, need to appear before the middleware this constraint is applied to (i.e. closer to the application)
- after: tuple[MiddlewareForwardRef | Middleware | MiddlewareFactory, ...] = ()¶
Tuple of middlewares that, if present, need to appear after the middleware this constraint is applied to (i.e. closer to the handler)
- first: bool = False¶
If
True, require the middleware to be the first (i.e. the first middleware on the application).Mutually exclusive with
last=True. Implicitly setsunique=True
- last: bool = False¶
If
True, require the middleware to be the last (i.e. the last middleware on the handler).Mutually exclusive with
first=True. Implicitly setsunique=True
- apply_before(other: str | Middleware | MiddlewareFactory | MiddlewareForwardRef, ignore_import_error: bool = False) Self[源代码]¶
Return new
MiddlewareConstraintswithotheradded to existingbeforeconstraint.- 参数:
other¶ -- Middleware this middleware needs to be applied before. If passed a string, create a
MiddlewareForwardRefthat resolves to the actual middleware at runtimeignore_import_error¶ -- If
Trueandotheris a string, ignore the constraint if anImportErroroccurs when trying to import it
- apply_after(other: str | Middleware | MiddlewareFactory | MiddlewareForwardRef, ignore_import_error: bool = False) Self[源代码]¶
Return new
MiddlewareConstraintswithotheradded to existingafterconstraint.- 参数:
other¶ -- Middleware this middleware needs to be applied before. If passed a string, create a
MiddlewareForwardRefthat resolves to the actual middleware at runtimeignore_import_error¶ -- If
Trueandotheris a string, ignore the constraint if anImportErroroccurs when trying to import it
- __init__(before: tuple[MiddlewareForwardRef | Middleware | MiddlewareFactory, ...] = (), after: tuple[MiddlewareForwardRef | Middleware | MiddlewareFactory, ...] = (), first: bool = False, last: bool = False, unique: bool | None = None) None¶
- class litestar.middleware.constraints.MiddlewareForwardRef[源代码]¶
基类:
objectForward reference to a middleware
- ignore_import_error: bool¶
If 'True', ignore
ImportErrors will be ignored when resolving the middleware
- resolve() Middleware | None[源代码]¶
Resolve the reference to a concrete value by importing the target path.
If
ignore_import_error=Trueand anImportErroris raised, ignore the error and returnNone