URL namespacing improvements
|Reported by:||Aymeric Augustin||Owned by:||Marten Kenbeek|
|Cc:||real.human@…, Ben Davis, dries@…, Florian Apolloner, info+coding@…, marten.knbk@…||Triage Stage:||Accepted|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
I discussed URL namespacing with Malcolm at DjangoCon US 2012. I took some notes on the current design and possible improvements.
Unfortunately, I haven't found the time and motivation to actually work on these improvements since then. I just mentioned them in #20734.
I'm including below a slightly edited version of my notes. Not everything is clear, but that's all I have, and I don't remember anything else.
URL namespaces only exist for the purpose of reversing. They're "names for groups of URLs".
(They're analogous to XML namespaces in this regard.)
- Apps need to be able to reverse their own URLs, even if there are several instances installed.
- It must be possible to find the default instance of an app.
- It must be possible to find a specific instance of an app.
Application vs. instance namespaces
An application namespace = app_name
- There can be only one in a given project.
- The only use case for not using the application label is name conflicts.
- Shouldn't it be eventually moved to app._meta? (not sure about what I meant there)
An instance namespace = namespace
- It differentiate instances of the same application.
1) Clarify documentation
2) Make it possible to reverse without specifying the namespace and document this pattern:
urlpatterns = ( url(r'^foo/', include('foo.urls', namespace='foo')), )
This requires a way to specifiy the default namespace. It would supersede #11642.
Change History (22)
comment:14 Changed 21 months ago by
|Owner:||changed from nobody to Marten Kenbeek|
|Status:||new → assigned|