#### `django-context` is an BSD licensed library written in Python. It could be helpful for you if you wanna set some custom context in your django app. The one of the examples is add an extra info into your logging records. Also, you can use a request object in any place of an application cause this library provides a capability to reach it out at any time during a request.
### Quick start
1 install the library:
```bash
pip install django-context
```
2 Add `django-context` to your INSTALLED_APPS setting like this:
```Python
INSTALLED_APPS = [
...
django_context,
]
```
3 Add proxy middleware to your MIDDLEWARE setting like this:
```Python
MIDDLEWARE = [
'django_context.middleware.ProxyMiddleware',
...
]
```
It's important to place this `ProxyMiddleware` at the first place in a `MIDDLEWARE` to allow to calculate duration of response more precisely.
4 If you just want to add info about request duration and request id to your log records then you can use `GlobalWSGIMiddleware` in your `wsgi.py` like this:
```Python
application = GlobalWSGIMiddleware(get_wsgi_application())
```
5 Use this example of logging setting to set up your loggers correctly
```Python
LOGGING = {
'version': 1,
'formatters': {
'verbose': {
'format': ('[django] %(levelname)s %(asctime)s'
' %(name)s/%(module)s'
' %(process)d/%(thread)d'
' request_id: %(request_id)s'
' user_id: %(user_id)s'
' duration: %(response_duration)s'
' %(message)s')
},
},
'filters': {
'context_filter': {
'()': 'django_context.logging.ContextFilter'
}
},
'handlers': {
'console': {
'level': 'INFO',
'class': 'logging.StreamHandler',
'formatter': 'verbose',
'filters': ['context_filter']
}
},
'loggers': {
'django_context': {
'level': 'INFO',
'handlers': ['console'],
'propagate': True,
},
'django': {
'level': 'INFO',
'handlers': ['console'],
'propagate': True,
},
}
}
```
### Log records example
<img src="./pictures/log_records_example.png" width="1200" height="130">
Metadata
Release files for django-context 0.1.1
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-context-0.1.1.tar.gz | 5.1 kB | Without provenance | Details for django-context-0.1.1.tar.gz |
Release files / django-context-0.1.1.tar.gz
| Download URL | django-context-0.1.1.tar.gz |
|---|---|
| Size | 5.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
54a47e3cb07dc1f71ac3e28e8c088f0f2bee8eb12f25e1e55d1c792701183eb1
|
|
BLAKE2b-256 checksum How to use checksums |
212e685e3c9daf9747a756716b11c5b12c5c27aae726a39904984cc20403e139
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.0 CPython/2.7.15
|
Security for django-context 0.1.1
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.