Let’s say I have an app users with an app_name of users
in its urls.py. I want to include those urls in an app with the app_name clients
and one with the app_name admins
.
So {% url 'clients:users:list' %}
resolves fine as does {% url 'admins:users:list" %}
but if I want to add a non-prefixed create link {% url 'users:create' %}
on the user list page, it won’t pick up on the top-level name space I am on and append it to users:create. Is there a good way to make this work?
If this is a case where you are including this template from another template, you might be able to pass the top level into the template and concatenate it with that literal.
Something to the effect of:
{% include "template.html" with prefix="clients" %}
Then, within that included template:
{% url prefix|stringformat:"s:users:create" %}
(Warning, winging this off-the-cuff - There may be a syntax error here.)
I was hoping I was just missing a way to feed the namespace into the url tag. When I inspect the request.resolver_match
I can see namespace
set to "clients:users"
and namespaces
set to ["clients", "users"]
. I guess I can alway just create an extended url tag.
What you’re describing should work according to the docs. Is the view that’s serving the response within one of those two apps?