I want to make a variable in my views.py which changes depending the name of the urlpattern used
<p>Here's my code. whatever urlpattern is chosen: I want the name of it to be stored as <code>url</code> in views.py. Which is then used in queryset filter().</p>

<p><strong>urls.py</strong></p>

<pre><code>url(r'^news/', BoxesView.as_view(), name='news'),
url(r'^sport/', BoxesView.as_view(), name='sport'),
url(r'^cars/', BoxesView.as_view(), name='cars'),
</code></pre>

<p><strong>views.py</strong></p>

<pre><code>class BoxesView(ListView):
    url = #urlname to go here
    def get_queryset(self):
        queryset_list = Post.objects.all().filter(category=url)
</code></pre>

<p><strong>models.py</strong></p>

<pre><code>category = models.CharField(choices=CATEGORY_CHOICES)
</code></pre>

<p><strong>choices.py</strong></p>

<pre><code>CATEGORY_CHOICES = (
    ('1', 'news'),
    ('2', 'sport'),
    ('3', 'cars'),

)
</code></pre>

<p>Any idea?</p>

<p>You can use this to get the name of the view</p>

<pre><code> url = resolve(self.request.path_info).url_name
</code></pre>

<p>UPDATE: Added "self." which is needed when using generic views. And don't forget to import:</p>

<pre><code> from django.core.urlresolvers import resolve
</code></pre>

python django django-views