constraints¶
- exception litestar.middleware.constraints.ConstraintViolationError[source]¶
Bases:
MiddlewareConstraintError
- exception litestar.middleware.constraints.CycleError[source]¶
Bases:
MiddlewareConstraintError
- exception litestar.middleware.constraints.MiddlewareConstraintError[source]¶
Bases:
LitestarException
- class litestar.middleware.constraints.MiddlewareConstraints[source]¶
Bases:
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[source]¶
Return new
MiddlewareConstraintswithotheradded to existingbeforeconstraint.- Parameters:
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[source]¶
Return new
MiddlewareConstraintswithotheradded to existingafterconstraint.- Parameters:
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[source]¶
Bases:
objectForward reference to a middleware
- ignore_import_error: bool¶
If ‘True’, ignore
ImportErrors will be ignored when resolving the middleware
- resolve() Middleware | None[source]¶
Resolve the reference to a concrete value by importing the target path.
If
ignore_import_error=Trueand anImportErroris raised, ignore the error and returnNone