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

Transfer URL to path (from Django 1.9 to Django 2.2.5

Hello I have to Url like this in django 1.9

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

How can I transfer to path() in Django 2.2.5

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

You may be able to use Django path() with the following signature:

path(route, view, kwargs=None, name=None)

or Django re_path with the signature:

*re_path(route, view, kwargs=None, name=None)

So

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

becomes either

   path('<int:course_pk>/<int:step_pk>/', views. step_detail),
   path('<int:pk>/$', views.course_detail),

# or 

   re_path(r'(?P<course_pk>\d+)/(?P<step_pk>\d+)/$', views.step_detail),
   re_path(r'(?P<pk>\d+)/$', views.course_detail),

Post back if you need more help. Good luck!!!