I'm getting a strange error from the Django tests, I get this error when I test Django or when I unit test my story app. It's complaining about multiple block tags with the name "content" but I've renamed all the tags so there should be zero block tags with the name content. The test never even hits my app code, and fails when I run django's test suite too.
The application runs fine, but I'm trying to write unit tests, and this is really getting in the way.
Here's the test from story/tests.py:
class StoryViewsTests(TestCase):
def test_root_url_shows_home_page_content(self):
response = self.client.get(reverse('index'))
...
Here's the view from story/views.py:
class FrontpageView(DetailView):
template_name = "welcome_content.html"
def get_object(self):
return get_object_or_404(Article, slug="front-page")
def get_context_data(self, **kwargs):
context = super(FrontpageView, self).get_context_data(**kwargs)
context['slug'] = "front-page"
queryset = UserProfile.objects.filter(user_type="Reporter")
context['reporter_list'] = queryset
return context
Here's the url from urls.py:
urlpatterns = patterns('',
url(r'^$', FrontpageView.as_view(), name='index'),
...
Here's the template:
{% extends "welcome.html" %}
{% block frontpagecontent %}
<div>
{{ object.text|safe}}
<div class="span12">
<a href="/accounts/register/">
<div class="well">
<h3>Register for the Nebraska News Service today.</h3>
</div> <!-- well -->
</a>
</div>
</div>
<div class="row-fluid">
<div class="span8">
<div class="well" align="center">
<img src="{{STATIC_URL}}{{ object.docfile }}" />
</div> <!-- well -->
</div> <!-- span8 -->
<div class="span4">
<div class="well">
<h3>NNS Staff:</h3>
{% for r in reporter_list %}
<p>{{ r.user.get_full_name }}</p>
{% endfor %}
</div> <!-- well -->
</div> <!-- span4 -->
</div>
{% endblock %}
And here's the trace:
ERROR: test_root_url_shows_home_page_content (story.tests.StoryViewsTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/vagrant/webapps/nns/settings/../apps/story/tests.py", line 11, in test_root_url_shows_home_page_content
response = self.client.get(reverse('about'))
File "/home/vagrant/django5/local/lib/python2.7/site-packages/django/test/client.py", line 473, in get
response = super(Client, self).get(path, data=data, **extra)
File "/home/vagrant/django5/local/lib/python2.7/site-packages/django/test/client.py", line 280, in get
return self.request(**r)
File "/home/vagrant/django5/local/lib/python2.7/site-packages/django/test/client.py", line 444, in request
six.reraise(*exc_info)
File "/home/vagrant/django5/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 152, in get_response
response = callback(request, **param_dict)
File "/home/vagrant/django5/local/lib/python2.7/site-packages/django/utils/decorators.py", line 99, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/home/vagrant/django5/local/lib/python2.7/site-packages/django/views/defaults.py", line 23, in page_not_found
template = loader.get_template(template_name)
File "/home/vagrant/django5/local/lib/python2.7/site-packages/django/template/loader.py", line 138, in get_template
template, origin = find_template(template_name)
File "/home/vagrant/django5/local/lib/python2.7/site-packages/django/template/loader.py", line 127, in find_template
source, display_name = loader(name, dirs)
File "/home/vagrant/django5/local/lib/python2.7/site-packages/django/template/loader.py", line 43, in __call__
return self.load_template(template_name, template_dirs)
File "/home/vagrant/django5/local/lib/python2.7/site-packages/django/template/loader.py", line 49, in load_template
template = get_template_from_string(source, origin, template_name)
File "/home/vagrant/django5/local/lib/python2.7/site-packages/django/template/loader.py", line 149, in get_template_from_string
return Template(source, origin, name)
File "/home/vagrant/django5/local/lib/python2.7/site-packages/django/template/base.py", line 125, in __init__
self.nodelist = compile_string(template_string, origin)
File "/home/vagrant/django5/local/lib/python2.7/site-packages/django/template/base.py", line 153, in compile_string
return parser.parse()
File "/home/vagrant/django5/local/lib/python2.7/site-packages/django/template/base.py", line 278, in parse
compiled_result = compile_func(self, token)
File "/home/vagrant/django5/local/lib/python2.7/site-packages/django/template/loader_tags.py", line 215, in do_extends
nodelist = parser.parse()
File "/home/vagrant/django5/local/lib/python2.7/site-packages/django/template/base.py", line 278, in parse
compiled_result = compile_func(self, token)
File "/home/vagrant/django5/local/lib/python2.7/site-packages/django/template/loader_tags.py", line 190, in do_block
nodelist = parser.parse(('endblock',))
File "/home/vagrant/django5/local/lib/python2.7/site-packages/django/template/base.py", line 278, in parse
compiled_result = compile_func(self, token)
File "/home/vagrant/django5/local/lib/python2.7/site-packages/django/template/loader_tags.py", line 186, in do_block
raise TemplateSyntaxError("'%s' tag with name '%s' appears more than once" % (bits[0], block_name))
TemplateSyntaxError: 'block' tag with name 'content' appears more than once