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 Final Details Step Detail View

Sahar Nasiri
Sahar Nasiri
7,454 Points

Urls

I didn't get it! Why do we have to put our course_detail after step_detail?

1 Answer

David Lin
David Lin
35,864 Points

I think it's due to Djano's use of regex pattern matching in the urls, so that the order in which a pattern is matched is important.

The course_detail url has one parameter, whereas the step_detail has two. The concern is that if course_detail with one parameter was used first, it would be sufficient to satisfy the regex pattern match criteria even if two parameters were present, thus, returning the course_detail instead of the step_detail if two parameters were present, which is incorrect.

On the other hand, by listing the step_detail first, the two-parameter regex pattern match will be used first to match, and return step_detail if two parameters are present. If not, then it will check if only one were present, and if so, return course_detail as expected.