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

Is there an order for the declaration of URLs, in urls.py ?

Hi,

In the code below, is there any recommended order for the declaration of urls?

urlpatterns = [
    path('', views.hello_world, name = 'home'),
    path('admin/', admin.site.urls),
    path('courses/', include('courses.urls', namespace='courses')),
    path('suggest', views.suggestion_view, name = 'suggestion'),
]

Thanks for the response

2 Answers

Jeff Muday
MOD
Jeff Muday
Treehouse Moderator 28,732 Points

Since the routes are evaluated in order, order is important. It is possible to insert a route at the beginning of the list that might interfere (or prematurely "intercept") a route that you meant to be interpreted in a different way. It is very important when you are using regular expressions, to terminate those with a '$' character.

Django 2.0 uses simpler syntax than the 1.10 (long term support release) https://docs.djangoproject.com/en/2.0/releases/2.0/

Some people favor the "alphabetized" convention you are showing in your example code.

Thanks Jeff!