views:

72

answers:

1

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?

A: 

Evidently, the tests were actually failing because Django couldn't find a Site record in the database. It may be because my SITE_ID is set to something other than 1; this was supposedly fixed, as mentioned in this ticket, but it doesn't seem to be actually fixed.

mipadi