11.4 Splitting Organizer urls.py

If you open the /organizer/urls.py file, you’ll discover that our urlpatterns list is quite long. What’s more, we’re defining the prefix to many of the URL patterns multiple times: our URL patterns all have regular expression patterns that start with /tag/, /startup/, or /newslink/. That is not desirable.

While Django convention dictates that our app contain all of the URL patterns in a urls.py file, there is absolutely no reason to adhere to this convention if breaking from convention makes our code cleaner. In this section, we split the urls.py file into several smaller modules, resulting in a url package.

To begin, we need to create a url directory in /organizer/and then create a file called --init--.py in ...

Get Django Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.