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

It's probably better if we use namespaces. I've put all of the articles URLs into the "articles" namespace. Change your

It's probably better if we use namespaces. I've put all of the articles URLs into the "articles" namespace. Change your {% url %} tag to use "articles:detail" for the URL name.

i need help guys im not understanding the question

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 %}
<a href="{%url 'articles_detail' pk=article.pk %}">{{ article.headline }}</a>
{% endfor %}
{% endblock %}

1 Answer

Jeff Muday
MOD
Jeff Muday
Treehouse Moderator 28,720 Points

Namespace is an important concept in Django. By introducing the namespace parameter, an entire app will have a "namespace" association. The namespace argument is introduced at the project level urls.py file. Once introduced, the namespace argument will allow the django app (and the other apps in the project) to resolve the path to find templates and methods of the app. This enhances portability/modularity of the app (you will be able to use your app in other projects) and can have multiple routes/instances of your app running on the same project.

Check out this documentation:

https://docs.djangoproject.com/en/2.1/topics/http/urls/#url-namespaces

I am paraphrasing what I think is the important code from the documentation

# filename: urls.py
# NOTICE THAT WE CAN USE SAME APP ON DIFFERENT ROUTES (author-polls and publisher-polls)
from django.urls import include, path

urlpatterns = [
    path('author-polls/', include('polls.urls', namespace='author-polls')),
    path('publisher-polls/', include('polls.urls', namespace='publisher-polls')),
]

Note that with the namespace, 'author-polls:index' will always resolve to the index page of the instance 'author-polls' (and likewise for 'publisher-polls') .

I hope this helps. Django is one of the most powerful frameworks for building secure/scalable/robust applications!