Skip to main content

Contains utils for storing and retreiving values from threadlocals, and middleware for placing the current Django request in threadlocal storage.

Project description

Setup/Usage

Install using pip install django-threadlocals

Add threadlocals.middleware.ThreadLocalMiddleware to your MIDDLEWARE_CLASSES setting. Then use it as follows:

Example usage:

from threadlocals.threadlocals import get_current_request

request = get_current_request()

Caveat Emptor

Storing the request in threadlocals goes against several django core developers' strong inclinations against using threadlocals. See this thread on django-users for a more in-depth discussion. We recommend you not do this unless you have a really good reason to do so. We feel like we had a really good reason (the only one we've come across so far): Having the request in threadlocals is the core piece that allowed us to build a true multi-tenant system on top of django where the site is resolved dynamically based on the current host, and objects are filtered based on the current host. With the current version of django, this is nearly impossible to do without the request in threadlocals. This was a very significant and advanced undertaking, but we're happy with the results.

Tests

To run tests:

python tester/manage.py test

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-threadlocals-0.10.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

django_threadlocals-0.10-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file django-threadlocals-0.10.tar.gz.

File metadata

  • Download URL: django-threadlocals-0.10.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.7.1 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.7.0

File hashes

Hashes for django-threadlocals-0.10.tar.gz
Algorithm Hash digest
SHA256 c06a4c6701a56bcca2acd0bd655aaa136501ab7e5e6327ab7245be629906432a
MD5 04f07e2b44922ad885bf38885b97eac7
BLAKE2b-256 60b48defa1d5de9efa81b75b90baccd8607de1a2abd24c0d25a630d9183a1b6f

See more details on using hashes here.

File details

Details for the file django_threadlocals-0.10-py3-none-any.whl.

File metadata

  • Download URL: django_threadlocals-0.10-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.7.1 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.7.0

File hashes

Hashes for django_threadlocals-0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 fd5e2cb36224163a53f326baddfc36251d150466234a16d8f97f54ad92bce89d
MD5 a4bfb06c32a7bc1ff19718d33c4815b6
BLAKE2b-256 0b02181f5c3e8f6da800bc8ee4089a38878842d6f1c65054f0ffc0bd042aad47

See more details on using hashes here.

Supported by

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