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 Django Basics Final Details URL tag In list template

task 1 of 2 url tag in template django basics

I've added URL names for you but I need you to add the HTML markup for the links. Use the {% url %} tag to create the href attribute for the <a> tag. The URL name is articles_detail and you need to provide the pk from the Article as the pk argument. Bummer! Didn't find the correct {% url %} usage. Preview Get Help Recheck work articles/templates/articles/article_list.html

1 {% extends 'base.html' %} 2 {% load static from staticfiles %} 3 ā€‹ 4 {% block static %} 5 <link rel="stylesheet" href="{% static 'css/styles.css' %}"> 6 {% endblock %} 7 ā€‹ 8 {% block content %} 9 {% for article in articles %} 10 "{% 'detail' pk=article.pk %}" 11 <a href="">{{ article.headline }}</a> 12 {% endfor %} 13 {% endblock %}

articles/templates/articles/article_list.html
{% extends 'base.html' %}
{% load static from staticfiles %}

{% block static %}
<link rel="stylesheet" href="{% static 'css/styles.css' %}">
{% endblock %}

{% block content %}
{% for article in articles %}
"{% 'detail' pk=article.pk %}"
<a href="">{{ article.headline }}</a>
{% endfor %}
{% endblock %}

3 Answers

Ryan Ruscett
Ryan Ruscett
23,309 Points

Hey,

It's hard to tell because you don't actually have any tags within the href so I am not sure if you just didn't put anything there to get the error, which would sound about right. Or if you put something wrong and it just didn't show up here.

the href tag is already created. so we need to put {% url %} in the href. Then we need to have the url, which is articles:details and than we need the pk. We want the article pk to be exact.

{% extends 'base.html' %}
{% load static from staticfiles %}

{% block static %}
<link rel="stylesheet" href="{% static 'css/styles.css' %}">
{% endblock %}

{% block content %}
{% for article in articles %}
<a href="{%url 'articles:detail' pk=article.pk %}">{{ article.headline }}</a>
{% endfor %}
{% endblock %}

Let me know if this works for you or if you have other issues I can try and answer.

Thanks!

Thanx Ryan but i have already figured it out .

An addition to this issue is that there is no mention of him adding a "namespace" to that URL. So my initial thought was to just add it like this:

<a href="{%url 'articles_detail' pk=article.pk %}">{{ article.headline }}</a>