constraints¶
- exception litestar.middleware.constraints.ConstraintViolationError¶
Bases:
MiddlewareConstraintError
- exception litestar.middleware.constraints.CycleError¶
Bases:
MiddlewareConstraintError
- exception litestar.middleware.constraints.MiddlewareConstraintError¶
Bases:
LitestarException
- class litestar.middleware.constraints.MiddlewareConstraints¶
Bases:
object
Constraints 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
MiddlewareConstraints
withother
added to existingbefore
constraint.- Parameters:
other¶ – Middleware this middleware needs to be applied before. If passed a string, create a
MiddlewareForwardRef
that resolves to the actual middleware at runtimeignore_import_error¶ – If
True
andother
is a string, ignore the constraint if anImportError
occurs when trying to import it
- apply_after(other: str | Middleware | MiddlewareFactory | MiddlewareForwardRef, ignore_import_error: bool = False) Self ¶
Return new
MiddlewareConstraints
withother
added to existingafter
constraint.- Parameters:
other¶ – Middleware this middleware needs to be applied before. If passed a string, create a
MiddlewareForwardRef
that resolves to the actual middleware at runtimeignore_import_error¶ – If
True
andother
is a string, ignore the constraint if anImportError
occurs when trying to import it
- class litestar.middleware.constraints.MiddlewareForwardRef¶
Bases:
object
Forward reference to a middleware
- ignore_import_error: bool¶
If ‘True’, ignore
ImportError
s 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=True
and anImportError
is raised, ignore the error and returnNone