whoisearth
whoisearth

Reputation: 4160

django - view returning no value?

I have the following basic views.py to test out doing queries based on the user.

def Vendor_Matrix(request):
    username = request.session.get('username','')
    queryset = User.objects.filter(username=username).values_list('user_permissions', 'username', 'first_name')
    return JSONResponse(queryset)

I'm logged in (using Mezzanine) into my site. I then have that view referenced in the following urls.py

from django.conf.urls import patterns, url
from api import views

urlpatterns = patterns('',
    url(r'^your-data/vendor-matrix/$', 'api.views.Vendor_Matrix'),
)

When I go to the URL it comes up with a blank page. specifically this -

[]

I can only imagine it's not registering the logged in user?

I've simplified my views.py even further - Definitely not registering the username that is logged in. It still returns nothing.

def Vendor_Matrix(request):
    username = request.session.get('username','')
    return HttpResponse(username)

Upvotes: 0

Views: 61

Answers (1)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798446

That's not where Django keeps the logged-in user...

return JSONResponse(operator.attrgetter('user_permissions', 'username', 'first_name')(request.user))

Upvotes: 1

Related Questions