In my Django templates, I have a couple pieces of code that are like this:
<a href="{% url root %}">Root</a>
They work properly when rendering the template. However, whenever I run my unit tests using Django's unit testing framework, I get the following error:
NoReverseMatch: Reverse for 'mysite.root' with arguments '()' and keyword arguments '{}' not found.
The root is named properly in urls.py
(url(r'^$', 'index', name='root')
) and, again, the error doesn't show up when browsing the site -- only during unit tests.
If I change the code to this:
{% url root as root_path %}
<a href="{{ root_path }}">Root</a>
the error also goes away. What's the problem with the first piece of code?