Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Retrieve current user id in urls.py

82 views
Skip to first unread message

Peter Edström

unread,
Nov 27, 2012, 10:37:19 AM11/27/12
to django...@googlegroups.com
Hello,

I've set up a user profile according to this and now I'm trying to access the id of the currently logged in user in my urls.py, like this:

# urls.py 
from django.contrib.auth.decorators import login_required
from django.views.generic import list_detail
from myproj.myapp.models import App1

app1_info = {
        'queryset': App1.objects.filter(employee=????????)),
        'template_name': 'template.html',
}

urlpatterns = patterns('',
(r'^logged_in/$', login_required(list_detail.object_list), app1_info),
)


In App1 I have a OneToOneField to my user profile, I want to list everything in App1 filtered on the currently logged in user (employee = current_user).
Every example I find in the docs uses the request.user.username, but I have no request method here.

Any clues?

Daniel Roseman

unread,
Nov 27, 2012, 11:33:12 AM11/27/12
to django...@googlegroups.com
This isn't something you do in the urlconf. You do that in your view, where the current user is available already as `request.user`.
--
DR. 

Peter Edström

unread,
Nov 28, 2012, 6:38:37 AM11/28/12
to django...@googlegroups.com
Thank you. It's quite logical when you know it. :-)
Reply all
Reply to author
Forward
0 new messages