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 Django Templates Add a Detail View

Team GDiz
PLUS
Team GDiz
Courses Plus Student 24,942 Points

Page not found at courses/1

Hi guys am getting the following error for Add a detail view.

Page not found (404) Request Method: GET Request URL: http://localhost:8000/courses/1/ Using the URLconf defined in tester.urls, Django tried these URL patterns, in this order: ^courses/ ^$ ^courses/ ^$ ^admin/ ^$ ^static\/(?P<path>.*)$ The current URL, courses/1/, didn't match any of these.

Cannot see the detail page.

This is the regex i use for the url -

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

Any idea where I could be going wrong?

Dmitry Karamin
Dmitry Karamin
10,099 Points

try

url(r'courses/(?P<pk>\d+)/$', views.course_detail)

2 Answers

Make sure in your learning_site/urls.py you have the following, and then your code in courses/urls.py would have the routes for the course detail page:

urlpatterns = [
    url(r'^courses/', include('courses.urls', namespace='courses')),
    url(r'^admin/', include(admin.site.urls))
]

Thanks this helped me :)

Jeremy Nootenboom
seal-mask
.a{fill-rule:evenodd;}techdegree
Jeremy Nootenboom
Python Web Development Techdegree Student 6,876 Points

I had this problem as well, your solution fixed it. Thanks!

Kenneth doesn't have this in the video though. Is the version of Django he's using in the video deprecated? This is confusing for those just learning the basics.