Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit bb9f94a

Browse files
documented base async middleware
1 parent bb24627 commit bb9f94a

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ these tools are provided for now:
2222
2. async generic class based views.
2323
3. async paginator
2424
4. async auth mixins
25+
5. async base middleware
2526

2627
more to come...
2728

‎docs/index.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ check out the [installation](installation.md) guide for how to get this package.
1111
* async generic class based views.
1212
* async auth mixins.
1313
* async paginator.
14+
* async base middleware
1415
* more to come...
1516

1617
## Rational

‎docs/middleware/base.md‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
## AsyncMiddlewareMixin
2+
3+
a base class to create async only middlewares.
4+
5+
it is very similar to django's [MiddlewareMixin](https://docs.djangoproject.com/en/5.1/topics/http/middleware/#upgrading-pre-django-1-10-style-middleware)
6+
with the following specification:
7+
8+
`__call__` method is async, so you need to `await` the middleware instance.
9+
```pycon
10+
>>> middleware = AsyncMiddlewareMixin(get_response)
11+
>>> await middleware()
12+
```
13+
where `get_response` is an async function, sync functions are not supported and will raise an error.
14+
15+
----------------------------
16+
17+
other methods are as follows:
18+
19+
* `process_request` and `process_response` are `await`ed inside the middleware and have to be async
20+
21+
* `process_view` and `process_template_response` can be either sync or async, but **async is preferred**, if it's sync django will wrap it as async which might have slight performance reduction.
22+
23+
* `process_exception` can be either sync or async, but **sync is preferred**, if async is used django wraps the method to be called synchronously.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /