Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Shiqin Huo
Shiqin Huo
7,621 Points

Finish the test_detail_template test by using assertTemplateUsed to check that the correct template is used when you get

Finish the test_detail_template test by using assertTemplateUsed to check that the correct template is used when you get() the articles:detail URL. Remember to pass the pk of self.article when you use reverse!

Really confused by what's going wrong :(

my code in articles/tests.py:

import datetime

from django.core.urlresolvers import reverse
from django.test import TestCase

from .models import Article, Writer

class ArticleDetailViewTestCase(TestCase):
    '''Tests for the Article detail view'''

    def setUp(self):
        self.writer = Writer.objects.create(
            name='Kenneth Love',
            email='kenneth@teamtreehouse.com',
            bio='Your friendly, local Python teacher'
        )
        self.article = Article.objects.create(
          writer=self.writer,
          headline='Article 0',
          content='Something about 0',
          publish_date=datetime.datetime.today()
        )

    def test_detail_template(self):
        '''Make sure the `articles/article_detail.html` template is used'''
        resp = self.client.get(reverse('articles:detail', kwargs={'pk': self.article.id}))
        self.assertTemplateUsed(resp, 'articles/templates/articles/article_detail.html')


    def test_detail_template_writer(self):
        '''Make sure the article writer's name is in the rendered output'''
        resp=self.client.get(reverse('articles:detail',kwargs={'pk': self.article.pk}))
        self.assertContains(resp,self.article.writer.name) #include .name 

my code in articles/templates/articles/article_detail.html:

{% extends 'base.html' %}

{% block content %}
<h1>{{ article.title }}</h1>
<time>{{ article.publish_date }}</time>
<p>By {{ article.writer.name }}</p>
{{ article.content }}
{% endblock %}

2 Answers

I'm having the same issue. Is the question broken?

Han Li
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Han Li
Python Web Development Techdegree Graduate 14,817 Points

Hi

use this self.assertTemplateUsed(resp, 'articles/article_detail.html')

instead of self.assertTemplateUsed(resp, 'articles/templates/articles/article_detail.html')

Thanks Borys