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 trialAmmar Fatihallah
7,417 PointsGetting a No reverse match for 'course'
Just until 5:27, everything was working properly, I ran django and is started showing me a no reverse match for course at /' . Here's my code:
layout.html:
{% load static from staticfiles %}
{% load course_extras %}
<!doctype html>
<html>
<head>
<title>{% block title %}{% endblock %}</title>
<link rel="stylesheet" href="{% static 'css/layout.css' %}">
{% block static %}{% endblock %}
</head>
<body>
<div class="site-container">
<div>{% nav_course_list %}</div>
<nav>
<a href="{% url 'views.hello_world' %}">Home</a>
<a href="{% url 'courses:list' %}">Courses</a>
</nav>
<p>Don't miss our newest course, {% newest_course %}</p>
{% block content %}{% endblock %}
</div>
</body>
</html
course_extras.py:
from django import template
from courses.models import Course
register = template.Library()
@register.simple_tag
def newest_course():
'''Get the recent course from the courses library. '''
return Course.objects.latest('created_at')
@register.inclusion_tag('courses/course_nav.html')
def nav_course_list():
''' Returns a list of courses to display as nav pane. '''
courses = Course.objects.all()
return {'courses': courses}
and course_nav.html:
{% for course in courses %}
<div><a href="{% url 'course:detail' pk=course.pk %}">{{ course.title }}</a></div>
{% endfor %}
Any sggestions ?
Ammar Fatihallah
7,417 PointsHere's learning_site/url.py:
"""learning_site URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/1.8/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. Add an import: from blog import urls as blog_urls
2. Add a URL to urlpatterns: url(r'^blog/', include(blog_urls))
"""
from django.conf.urls import include, url
from django.contrib import admin
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from . import views
urlpatterns = [
url(r'^courses/', include('courses.urls', namespace='courses')),
url(r'^admin/', include(admin.site.urls)),
url(r'^$', views.hello_world),
]
urlpatterns += staticfiles_urlpatterns()
Here's learning_site/courses/url.py:
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.course_list, name='list'),
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'),
]
1 Answer
Chris Freeman
Treehouse Moderator 68,441 PointsYour namespace is set to courses
but the url is trying to look up course:detail
Post back if this doesn't fix it.
Ammar Fatihallah
7,417 PointsIndeed, thanks a lot ? ? ? !!
oliverchou
20,886 PointsI came across the same problem, but still, don't know how to deal with it with this information.
Can you tell me how to modify?
Chris Freeman
Treehouse Moderator 68,441 PointsChris Freeman
Treehouse Moderator 68,441 PointsCan you share your url.py code?