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 Customizing Django Templates Building Custom Tags DIY Custom Tags

How to link directly to the newest course from the homepage?

Hi everyone,

I am trying to make an anchor tag for the newest course on the homepage, however when I try to make the url I get an error. It seems like you cannot have nested tags. I was trying the following:

<a href="{% url 'courses:detail' pk={% newest_course %}.pk %}">{% newest_course %}</a>

Would anyone else be able to provide a solution to this?

Thanks!

Chris Freeman
Chris Freeman
Treehouse Moderator 68,454 Points

Have you tried:

<a href="{% url 'courses:detail' pk=newest_course.pk %}">{% newest_course %}</a>

(formatted using ```html+jinja )

1 Answer

divide_by_zero.rb:2:in `/': divided by 0 (ZeroDivisionError) . Doesn't work.

newest_course.pk doesn't give the pk instead returns an empty string based on the error observed (see below)

NoReverseMatch at /courses/

Reverse for 'detail' with arguments '()' and keyword arguments '{u'pk': ''}' not found. 1 pattern(s) tried: [u'courses/(?P<pk>\\d+)/$']