django-g
Django global context to get current request from anywhere in your application.
Many scenarios need the current request but Django don't have it accessible. They expect that your application implement a middleware to use the request, but it is burdensome and not reusable.
Other packages, like django-threadlocals do the same thing with threadlocals, but it doesn't work on the async world.
How to install
$ pip install django-g
How to use
Add django_g.middleware.RequestMiddleware to your settings MIDDLEWARE. It
is a small middleware just to capture the current request and save to global
context, ordering probably doesn't matter because any other middleware
already have access to the request.
MIDDLEWARE = [
"django_g.middleware.RequestMiddleware",
...
]
from django_g import get_current_request
def your_func():
request = get_current_request()
# Use the request here. Be careful and handle when `request=None`.
protip It is not a good idea to get the request everywhere, because you're coupling the framework specifics with your logic, so use this package only to get the request where you don't have a better way.
Metadata
Release files for django-g 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django-g-0.0.2.tar.gz | 3.4 kB | Without provenance | Details for django-g-0.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_g-0.0.2-py3-none-any.whl | Python 3 | none | any | Details for django_g-0.0.2-py3-none-any.whl |
Total release size: 7.3 kB
Release files / django-g-0.0.2.tar.gz
| Download URL | django-g-0.0.2.tar.gz |
|---|---|
| Size | 3.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3eb6e33a95849e4159c211e792ae2801f909660737eca4551360ac2bc7a65366
|
|
BLAKE2b-256 checksum How to use checksums |
5b8bfb5f3d59f218198f679c81ed18fa6440cfb2b6faa313521b6604c1447f03
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.16
|
Release files / django_g-0.0.2-py3-none-any.whl
| Download URL | django_g-0.0.2-py3-none-any.whl |
|---|---|
| Size | 4.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c7c10f5cfcdb321c34f8b3e144759d6536c8eb16144d57b179b96191e5c94c0e
|
|
BLAKE2b-256 checksum How to use checksums |
0fca2d6742407598d098f1adbaa3e55e961a0c6f3f3c9efa3df1db77256befee
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.16
|
Security for django-g 0.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.