4👍
✅
The RemoteUserBackend
(from django.contrib.auth.backends
) uses special middleware, RemoteUserMiddleware
, to access request data. Maybe you could do it this way, too.
6👍
You can use the tiny ThreadLocalMiddleware. It makes the request object everywhere available.
from django_tools.middlewares import ThreadLocal
request = ThreadLocal.get_current_request()
# request.session <-- is now available
Do not forget to add the middleware into the MIDDLEWARE_CLASSES tuple of your settings.py:
MIDDLEWARE_CLASSES = (
...
'django_tools.middlewares.ThreadLocal.ThreadLocalMiddleware',
...
)
- Django NodeNotFoundError during migration
- Django – Override admin site's login form
- Django 'function' object has no attribute 'objects'
- What's the best way to use CoffeeScript with Django if you're developing on Windows?
- Django crontab not executing test function
0👍
You can also pass a ‘request’ parameter to the authenticate
function any time you call it:
def authenticate(self, request, **kwargs):
....
- How to map PostgreSQL array field in Django ORM
- Django Test Client post() returns 302 despite error on view's post()
Source:stackexchange.com