Skip to main content

Django middleware which provide request and g objectall of which are accessible everywhere, and thread isolation, just like used in flask.

Project description

django-context-request

Django middleware which provide request and g object. all of which are accessible everywhere, and thread isolation, just like used in flask.

Installing

Install and update using pip:

pip install django-context-request

Usage

  1. Add RequestContextMiddleware to MIDDLEWARE in settings.py
import django_request_context

MIDDLEWARE = [
   ...
   'django_request_context.RequestContextMiddleware',
   ...
   ] 
  1. You can get request and g objects anywhere in the project throughout the life cycle of the request. just import:
from django_request_context import request, g

why do you need this?

when your django project is big enough and the function call stack is deep. if your want to get request object in the bottom of the call stack, you need to transfer request as parameters layer-by-layer, this can help you get request directly. the request you import from django-request-context is readonly object, if your want to convey some message you can user g object, this is a writeable object. the behavior of the request and g objects is exactly the same as in the flask.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_context_request-0.1.0.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

django_context_request-0.1.0-py2.py3-none-any.whl (5.1 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file django_context_request-0.1.0.tar.gz.

File metadata

  • Download URL: django_context_request-0.1.0.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.10

File hashes

Hashes for django_context_request-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0ea635f4e3fcd95bdbe2d9db4389c9a5fb6d1fcfc4cdc991c55850801ec7e667
MD5 0d2259ab3ed6a6e4ddd8e54e4cc6022b
BLAKE2b-256 fd6a2f9b3fb393513e62cef91ba6ba6f38dda1751cd9060dc099c3cc59a763bb

See more details on using hashes here.

File details

Details for the file django_context_request-0.1.0-py2.py3-none-any.whl.

File metadata

  • Download URL: django_context_request-0.1.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.10

File hashes

Hashes for django_context_request-0.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 a4b5cc1540620da7b7ecb4110e966eaf6a2eb14d9488b85386695a17ff2690e6
MD5 cb6436b5b449596c124c4bfd2267de83
BLAKE2b-256 0dc680722f897c2ae1359aaa01f7ad734160b7162f8447ad74a9c376c4b424f4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page