Namespace url lookup inside template of an app

15 views
Skip to first unread message

Thorsten Sanders

unread,
Jan 29, 2015, 3:25:32 PM1/29/15
to django...@googlegroups.com
Hello,

writing currently an app which should show different things based on
namespace which is working already, but I do have problems with
generating the right url inside the templates of that app.
I tried to use:
{% url 'myaddons:index' %}
but that always shows the same namespace url the last one attached.

Currently have defined inside that app:
urlpatterns = patterns('',
url(r'^$', 'myaddons.views.index', name='index'),
)

Then have 2 other apps in one I define:
urlpatterns = patterns('',
url(r'^addons/', include('myaddons.urls',
namespace='wow-myaddons', app_name='myaddons')),
)

in the other one:
urlpatterns = patterns('',
url(r'^addons/', include('myaddons.urls', namespace='ws-myaddons',
app_name='myaddons')),
)

The base one is:

url(r'^wow/', include('warcraft.urls')),
url(r'^ws/', include('wildstar.urls')),

With what I tried it always resolve to:
/ws/addons/

I want it to resolve to:
/wow/addons/ if called with /wow/
and
/ws/addons/ if called with /ws/

Greetings,
Thorsten

Thorsten Sanders

unread,
Jan 30, 2015, 8:00:54 AM1/30/15
to django...@googlegroups.com
Answering my own question, for the case someone else need it:

I am used to use render_to_response it not working with it, with using
render it works with applying current_app, like this:

return render(request, 'myaddons/index.html',
{'addons':addons,'game':game,},current_app=request.resolver_match.namespace)
Reply all
Reply to author
Forward
0 new messages