[Fixed]-I want to make a variable in my views.py which changes depending the name of the urlpattern used

1👍

I would replace your url.py by something like this:

url(r'(?P<keyword>\w+)/$', BoxesView.as_view())

This changes your address into an url parameter which you can then access the in your methods like this:

def get_queryset(self):
            url = self.kwargs['keyword']
            queryset_list = Post.objects.all().filter(category=url)

0👍

You can use this to get the name of the view

 url = resolve(self.request.path_info).url_name

UPDATE: Added “self.” which is needed when using generic views. And don’t forget to import:

 from django.core.urlresolvers import resolve

Leave a comment