Opened 14 years ago

Closed 14 years ago

#14505 closed (invalid)

Multiple Namespaces and reverse lookup does not work as advertised.

Reported by: dcurtis Owned by: nobody
Component: Core (Other) Version: 1.2
Severity: Keywords: namespace application reverse
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

### urls.py
urlpatterns = patterns('',
    (r'^butter/', include(milkpost.urls, namespace="butter", app_name='milkpost')),
    (r'^newsletter/', include(milkpost.urls, namespace="newsletter", app_name='milkpost')),
    (r'^admin/', include(admin.site.urls)),
)

### milkpost.urls
def myview(request):
    return render_to_response('milkpost/main.html')

urlpatterns = patterns('',
        url(r'^myview', myview, name='myview'),
)


### main.html
{% load markup %}
<head>
    <title>main - milkbox</title>
</head>
<body align="center">
    {% url milkpost:myview %}
</body>

both urls: /newsletter/myview/ and /butter/myview/
print out /newsletter/myview/

As the following page points out,
http://docs.djangoproject.com/en/dev/topics/http/urls/#url-namespaces

two instances of the same app should be distinguishable. This does not happen though and can be very frustrating!

Change History (2)

comment:1 by Frank Wiles, 14 years ago

The docs aren't super clear, but after a quick read shouldn't your template just use {% url myview %} and then it will resolve properly inside each app? By using 'milkpost:myview' you're actually telling it to use the last installed instance ( i.e /newsletter/ ) here.

comment:2 by Russell Keith-Magee, 14 years ago

Resolution: invalid
Status: newclosed

This is working as designed. As Frank notes, 'milkpost:myview' is referencing the app namespace using the default name. If you want to differentiate them, you need to either use 'butter:myview' or 'newsletter:myview' to differentiate the instances, *or* pass in a current_app as part of the context when rendering the view.

As for the docs not being clear... I thought they were. They describe the step by step process, and gives an example as well. Suggestions on how to clarify the docs are welcome.

Note: See TracTickets for help on using tickets.
Back to Top