djangosnippets.org: Latest snippets tagged with 'local thread'https://djangosnippets.org/tags/local-thread/2010-08-30T04:51:09.100236-05:00Get current user without a request object
2010-08-30T04:51:09.100236-05:00t_rybikhttps://djangosnippets.org/snippets/2179/<p>Mechanism to obtain a <code>request.user</code> object without the <code>request</code> object itself. Requires <code>LocalUserMiddleware</code> in <code>MIDDLEWARE_CLASSES</code> settings variable.
</p>
<p><strong>Important</strong>: works under assumption that within a web server each request is handled by a separate thread (as for example in the Apache HTTP server).
</p>
<p><strong>Beware</strong>: <a href="http://code.djangoproject.com/wiki/CookBookThreadlocalsAndUser">security threat</a>, although <a href="http://groups.google.com/group/django-users/browse_thread/thread/e7af359d7d183e04">"thread …</a></p>
Freely redistributable