Split URLs into application specific urlconfs
This is off the back of a discussion on gitter.
Right now we have most URLs defined in one big monolithic URLs config file. This makes maintaining it more difficult than necessary and a regular source of merge conflicts.
Instead we should be splitting urls into their respective apps and importing the apps urlpatterns
into our root file. This allows us to keep all of an applications code together and gives us a nice neat root urlconf.
If we wanted to hard code imports we could do something like:
import example.urls
urlpatterns += example.urls.urlpatterns
with example.urls
like:
from django.conf.urls import include, url
from django.conf.urls.i18n import i18n_patterns
from django.utils.translation import ugettext_lazy as _
from . import views
app_urls = [
url(r'^/$', views.example_view, name='auth_example_view'),
]
app_i18n_urls = [
# i18n urls
]
urlpatterns = [
url(r'^example/', include(app_urls)),
]
urlpatterns += i18n_patterns(
url(r'^example/', include(app_i18n_urls))
)
or something along those lines.
Alternative to statically importing we could iterate through all installed apps looking for urls
modules to import urlpatterns
from. This may not be desirable as it could import urls from an external app that we don't want, and the services will have their urls imported twice as the services hook (will have) already added them. We could also just use a new urls
hook to register them in each app.
I'm fine with just having the urls statically imported for now.
Bonus points for future apps using url namespaces, but I think changing existing apps will break a lot of peoples template customisations and just isn't useful enough to warrant the work required.