Code

Opened 4 years ago

Closed 4 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: UI/UX:

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!

Attachments (0)

Change History (2)

comment:1 Changed 4 years ago by frankwiles

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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 Changed 4 years ago by russellm

  • Resolution set to invalid
  • Status changed from new to closed

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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.