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

Paulo Longino
Paulo Longino
5,017 Points

URLpatterns for Django 2 is quite different it can't accept regular expressions any help

WARNINGS: ?: (2_0.W001) Your URL pattern '(<pk>\d+)/$' [name='course_detail'] has a route that contains '(?P<', begins with a '^', or ends with a '$'. This was likely an oversight when migrating to django.urls.path().

2 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

According to the What's New in Django 2.0 docs, you can use re_path in place of url to use the legacy regular expression format, or covert to the new path format

    path('<int:pk>/', name='course-detail'),

Though your code seems to be missing the view argument that should follow the URL expression. See path documentation.

Post back if you have more questions. Good luck!!

Thanks again for the update Chris Freeman

Here's what I did to get my code to work correctly using Django v. 2.0.3

From the learning_sites/courses/urls.py

from django.urls import path

from . import views


urlpatterns = [
    path('', views.course_list),
    path('<int:pk>/', views.course_detail),
]