1

I want to add an additional dictionary to userena's profile detail view, but I cant figure out how to add extra_context to the view in my urls.py. The error is VariableDoesNotExist:

thing_list = {
    'queryset' : Thing.objects.all(),
    'template_object_name' : 'thing',
}

from userena import views as userena_views

url(r'^(?P<username>(?!signout|signup|signin)[\.\w-]+)/$',
   userena_views.profile_detail,
   {'extra_context':{'thing_list': thing_list}},
   name='userena_profile_detail'),

I am basing this on the answer to this SO question:

Adding extra_context in Django logout built-in view

Thanks for your ideas!

Community
  • 1
  • 1
Nick B
  • 9,267
  • 17
  • 64
  • 105

1 Answers1

2

It should be

thing_list = {
    'queryset' : Thing.objects.all(),
    'template_object_name' : 'thing',
    'extra_context': {'swamp_things': Thing.objects.filter(type='swamp')},
}

url(r'^(?P<username>(?!signout|signup|signin)[\.\w-]+)/$',
   userena_views.profile_detail,
   thing_list,
   name='userena_profile_detail'),

As for your latest comment (how to get the request into the queryset filtering).

views.py

from django.views.generic import list_detail

def requestuserswampers(request):
    qs = Thing.objects.filter(user=request.user)
    return list_detail.object_list(
                request,
                queryset = Thing.objects.all(),
                template_object_name = 'thing',
                extra_context = {'swamp_things': qs},
    )

And in your urls.py

from views import requestuserswampers

url(r'^(?P<username>(?!signout|signup|signin)[\.\w-]+)/$',
       requestuserswampers,
       name='userena_profile_detail'),

Reading the documentation for Generic Views is very good and it will teach you a lot as how the Generic Views actually work and what you can do with them!

Henrik Andersson
  • 45,354
  • 16
  • 98
  • 92
  • Oh ok. How can I include the queryset as the extra_context though?? – Nick B Jul 09 '13 at 19:50
  • Ok thanks! You answered my question, but just wondering now how to get the request ContextProcessor into this so that I can say `'extra_context': {'swamp_things': Thing.objects.filter(user=request.user)},` I would appreciate any ideas to help me get over this last hurdle, but thanks for your help so far! – Nick B Jul 09 '13 at 20:01
  • Yeah, I'll add it to the answer just for kicks ;) – Henrik Andersson Jul 09 '13 at 20:03
  • Thanks @limelights, I appreciate your help. But for some reason now there is a syntaxerror corresponding on line `'template_object_name' : 'thing',` Sorry to bother you but I feel so close to the solution.. – Nick B Jul 09 '13 at 20:41
  • Yeah, it's because a `:` snuck in there instead of a `=`. :) Sorry! – Henrik Andersson Jul 09 '13 at 20:42
  • Oh right thanks. Any idea why this may return `SyntaxError: keyword can't be an expression`? – Nick B Jul 09 '13 at 20:47
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/33161/discussion-between-limelights-and-nick-b) – Henrik Andersson Jul 09 '13 at 20:52