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 trialPatrick Bluth
13,285 PointsHow 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!
1 Answer
Deep Sukhwani
Courses Plus Student 2,359 Pointsdivide_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+)/$']
Chris Freeman
Treehouse Moderator 68,441 PointsChris Freeman
Treehouse Moderator 68,441 PointsHave you tried:
<a href="{% url 'courses:detail' pk=newest_course.pk %}">{% newest_course %}</a>
(formatted using ```html+jinja )