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

Reverse for 'list' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

Help! I've restarted this whole class twice now because I couldn't get past this - whenever I add a namespace, I immediately receive the error in the subject. Prior to that, all pages and links worked.

The error references the {% url 'courses:list' %} part from layout.html, but that seems fine?

urls.py:

from django.conf.urls import include, url
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.contrib import admin
from . import views

urlpatterns = [
    # Examples:
    # url(r'^$', 'learning_site.views.home', name='home'),
    # url(r'^blog/', include('blog.urls')),

    url(r'^courses/',include('courses.urls',namespace='courses')),
    url(r'^admin/', include(admin.site.urls)),
    url(r'^$',views.home,name='home'),
]
urlpatterns += staticfiles_urlpatterns()

app urls.py

from django.conf.urls import url
from courses import views

urlpatterns = [
    url(r'(?P<course_pk>\d+)/(?P<step_pk>\d+)/$',views.step_detail,name="step"),
    url(r'(?P<pk>\d+)/$',views.course_detail,name="detail"),
    url(r'^$',views.course_list,name="courses"),
]

layout.html:

<!DOCTYPE html>
{% load static from staticfiles %}
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>{% block title %}{% endblock title %}</title>
    <link rel="stylesheet" href="{% static 'css/layout.css' %}">
</head>
<body>
    <div class="site-container">
        <nav>
            <a href="{% url 'home' %}">Home</a>
            <a href="{% url 'courses:list' %}">Course List</a>

        </nav>
    {% block content %}

    {% endblock content %}
    </div>
</body>
</html>

course_list.html

{% extends "layout.html" %}

{% block title %}Available Courses{% endblock title %}

{% block content %}
    <div class="cards">
    {% for course in courses %}
        <div class="card">
            <header><a href="{% url 'courses:detail' pk=course.pk %}">{{course.title}}</a></header>
            <div class="card-copy">
                {{course.description}}
            </div>
        </div>
        {% endfor %}
    </div>


{% endblock content %}

1 Answer

Hi Blaine

You have named the url that lists all the courses in the app.urls as 'courses' , shouldn't this be called 'list'?

urlpatterns = [
    url(r'(?P<course_pk>\d+)/(?P<step_pk>\d+)/$',views.step_detail,name="step"),
    url(r'(?P<pk>\d+)/$',views.course_detail,name="detail"),
    #error is here i think
    url(r'^$',views.course_list,name="courses"),
    # try this
    url(r'^$',views.course_list,name="list"),
]

let me know if this works

omg. That's a little embarrassing.. Thanks Andreas!

Dont worry, i have made so many errors like this

Thanks, you save my life :)