Comments on: Get User from session key in Django http://scottbarnham.com/blog/2008/12/04/get-user-from-session-key-in-django/ Code and comments on web development, Django, Python and things (un)related. Wed, 03 Apr 2013 13:15:20 +0000 hourly 1 http://wordpress.org/?v=4.3 By: Jeremy Dunck http://scottbarnham.com/blog/2008/12/04/get-user-from-session-key-in-django/comment-page-1/#comment-611 Mon, 05 Jan 2009 14:17:06 +0000 http://scottbarnham.com/blog/2008/12/04/get-user-from-session-key-in-django/#comment-611 You shouldn’t assume that DB-backed sessions are used, or that the auth session item is “_auth_user_id”.

I’ve posted a snippet to show a backend-agnostic way to do this:
http://www.djangosnippets.org/snippets/1276/

]]>
By: Jj http://scottbarnham.com/blog/2008/12/04/get-user-from-session-key-in-django/comment-page-1/#comment-595 Fri, 05 Dec 2008 19:42:23 +0000 http://scottbarnham.com/blog/2008/12/04/get-user-from-session-key-in-django/#comment-595 Great information, it should be part of the error page and also be included in the error messages send to ADMINS on production sites.

]]>
By: omtv http://scottbarnham.com/blog/2008/12/04/get-user-from-session-key-in-django/comment-page-1/#comment-594 Fri, 05 Dec 2008 01:57:39 +0000 http://scottbarnham.com/blog/2008/12/04/get-user-from-session-key-in-django/#comment-594 This is quite a useful script!
I was just trying to do sth like this with swfupload. Thanks.

]]>
By: Doug Napoleone http://scottbarnham.com/blog/2008/12/04/get-user-from-session-key-in-django/comment-page-1/#comment-592 Thu, 04 Dec 2008 22:53:58 +0000 http://scottbarnham.com/blog/2008/12/04/get-user-from-session-key-in-django/#comment-592 The django-command-extensions project has this as a management command ‘print_user_for_session’:

http://code.google.com/p/django-command-extensions/

]]>
By: Viktor http://scottbarnham.com/blog/2008/12/04/get-user-from-session-key-in-django/comment-page-1/#comment-591 Thu, 04 Dec 2008 22:17:00 +0000 http://scottbarnham.com/blog/2008/12/04/get-user-from-session-key-in-django/#comment-591 Nice idea indeed, but actually it would be even better to have it called automatically when django shows the error page to the user. Not surprisingly this is easy to achieve by overwriting the default 500 error handler view in your urlconf.

The default says:

“handler500 = ‘django.views.defaults.server_error’“ in “django.conf.urls.defaults“

that you have imported anyway, so just write your own and be careful not to enter an endless 500 error loop. :)

]]>