Registry / devops / django-threadlocals

django-threadlocals

JSON →
library0.10pypypiunverified

Provides utilities for storing and retrieving values from threadlocals, and middleware to place the current Django request in threadlocal storage. Version 0.10 appears stable but unmaintained since 2012.

pip install django-threadlocals
INSTALL
IMPORT
SIG · DJANGO-THREADLOCAL
D
django-threadlocals
devopspythonv0.10
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

get_request
from threadlocals import get_request
from threadlocals import get_request
VERSION
from threadlocals import VERSION

Add middleware, then retrieve the current request from anywhere.

import os; os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project.settings') # In settings.py: MIDDLEWARE = [ 'threadlocals.middleware.ThreadLocalMiddleware', # ... other middleware ] # In your code: from threadlocals import get_request request = get_request() if request: print(request.user)
Debug
Known issues
gotchaget_request() can return None if called outside request-response cycle (e.g., celery tasks). Always check for None.
fix
if request := get_request(): ... else: handle_without_request()
affects: all
deprecatedLibrary is unmaintained since 2012. No support for Django async views or ASGI.
fix
Consider replacing with django-currentuser or custom middleware.
affects: >=0.10
gotchaMiddleware must be placed before common middleware that depend on request.user (e.g., django.contrib.auth.middleware.AuthenticationMiddleware).
fix
Place ThreadLocalMiddleware near the top of MIDDLEWARE list.
affects: all
breakingDjango 1.10 changed MIDDLEWARE from MIDDLEWARE_CLASSES; old-style MIDDLEWARE_CLASSES not supported.
fix
Use MIDDLEWARE (list) in settings.py for Django >= 1.10.
affects: >=0.10
Upgrade
Version history
0.10latest on PyPI · released Jan 31, 2019
Audit
Dependencies
DjangorequiredMiddleware designed for Django request/response cycle
Agent activity
7 hits · last 30 days
node
6
Resources
django-threadlocals — pip install django-threadlocals · libregistry