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

NoReverseMatch at /courses/1/

Hello, I'm developing on my local machine using djnago I'm using version 1.11.15

I've went though every comment and tried everything that was suggested and still keep getting the same error. Here is my view:

{% load static from staticfiles %}

<!DOCTYPE html>
<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>
  <link rel="stylesheet" href="{% static 'css/layout.css'%}">
</head>
<body>
  <nav>
     <a href="{% url 'hello_world' %}">Hello World</a>
  </nav>
  {% block content %} {% endblock %}
</body>
</html>

My urls.py

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

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

urls.py located in learning_site

"""learning_site URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/1.11/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  url(r'^$', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  url(r'^$', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.conf.urls import url, include
    2. Add a URL to urlpatterns:  url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import url
from django.contrib import admin
from django.contrib.staticfiles.urls import staticfiles_urlpatterns

from django.conf.urls import include

from . import views

urlpatterns = [
    url(r'^courses/', include('courses.urls')),
    url(r'^admin/', admin.site.urls),
    # The first arg is the pattern. The Second part is the function to send the request to.
    url(r'^$', views.home),
]

urlpatterns += staticfiles_urlpatterns()

1 Answer

Have a look at this discussion.