django-middleware-global-request
Django middleware that keep request instance for every thread.
Install
pip install django-middleware-global-request
Note
- It's NOT good to use global request, you should pass the request instance from view to any where you want to use it.
- If you use the global request in Model layout, it means when you call the Model method from Django Shell, you get a None request.
Usage
-
Add django application django_global_request to INSTALLED_APPS in settings.py
INSTALLED_APPS = [ ... 'django_middleware_global_request', ... ]
-
Add GlobalRequestMiddleware to MIDDLEWARE in settings.py
MIDDLEWARE = [ ... 'django_middleware_global_request.middleware.GlobalRequestMiddleware', ... ]
-
Get request instance with function get_request from django_middleware_global_request.middleware
from django_middleware_global_request.middleware import get_request class TestModel(models.Model): field1 = models.CharField(max_length=32) def hello(self): request = get_request() ...
Releases
v0.2.0 2020/03/09
- Rename the core package from django_global_request to django_middleware_global_request so that it matches with the package name. Note: It's NOT backward compatible, all applications that using old name MUST do changes.
v0.1.2 2019/04/07
- Some changes.
v0.1.1 2018/02/28
- Some changes.
v0.1.0 2017/12/28
- First release.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file django-middleware-global-request-0.2.0.tar.gz.
File metadata
- Download URL: django-middleware-global-request-0.2.0.tar.gz
- Upload date:
- Size: 3.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
31f277741cd228a93ab676afab8e4a13c884b78e4feb72c3bccc40083fb22c1a
|
|
| MD5 |
0f2512e052fcdfed6e4438807ef5e7fc
|
|
| BLAKE2b-256 |
ceb8a4b6f3856c8efbaaeaa1b0299e059b2f5ef743a5e7f0ad4b0aa977ad6934
|