[Answered ]-Add Extra_Context to App View (urls.py)

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!

Leave a comment