Q: NoReverseMatch when using with tag to set URL pattern name I am getting an error saying:
NoReverseMatch at /books/
Reverse for 'urlvar' not found. 'urlvar' is not a valid 
view function or pattern name.

I guess the {% with %} tag is not working well in books/index.html
but I don't know how to solve this.
this is my code:
books/urls.py
from django.conf.urls import url
from books import views

urlpatterns = [
url(r'^$', views.BooksModelView.as_view(), name='index'),

url(r'^book/$', views.BookList.as_view(), name='book_list'),
url(r'^author/$', views.AuthorList.as_view(), name='author_list'),
url(r'^publisher/$', views.PublisherList.as_view(), name='publisher_list'),

url(r'^book/(?P<pk>\d+)/$', views.BookDetail.as_view(), name='book_detail'),
url(r'^author/(?P<pk>\d+)/$', views.AuthorDetail.as_view(), name='author_detail'),
url(r'^publisher/(?P<pk>\d+)/$', views.PublisherDetail.as_view(), name='publisher_detail'),
               ]

templates/books/index.html
{% extends 'base_books.html' %}

{% block content %}
<h2>Books Management Systemt</h2>
<ul>
{% for modelname in object_list %}
    {% with 'books:'|add:modelname|lower|add:'_list' as urlvar %}
        <li><a href="{% url 'urlvar' %}">{{ modelname }}</a></li>
    {% endwith %}
{% endfor %}
</ul>
{% endblock %}


A: urlvar is a variable, so you use urlvar in the {% url %} tag instead of the string 'urlvar'.
<li><a href="{% url urlvar %}">{{ modelname }}</a></li>

You can construct the URL pattern name in the tag if you prefer, or keep the with tag if you find that more readable.
<li><a href="{% url 'books:'|add:modelname|lower|add:'_list' %}">{{ modelname }}</a></li>

Since you are using the 'books: namespace when you reverse the urls, you should set app_name in your books/urls.py file.
from django.conf.urls import url
from books import views

app_name = 'books'

urlpatterns = [
    ...
]

