url(r'^view/(\d+)$', views.view, name="view")
url(r'^author-polls/', include('polls.urls', namespace='author-polls', app_name='polls')), url(r'^publisher-polls/', include('polls.urls', namespace='publisher-polls', app_name='polls')),
there is two approaches:you can either create unique names for each url pattern entry like url(...., name='my_app_unique_view_name')
or use namespace and pass it to reverse like reverse('my-app-namespace:my-url-pattern-view-name')
You use the app namespace which you defined in the site for each app, not the app_name. That's what pa xapy meant.
In the example you gave it would be like: reverse('author-polls:view', self.id).
Well, as this is implemented you have to know your namespaces during development. But now i see what's your problem.I'm not sure, but i don't think it is encouraged to have multiple instances of the same app in one project. I think the sites contrib app or some other method of having this author/publisher distinction within the same app would better suit your needs.
Namespaces are a mess, and have been for a while. 1.9 cleans this up a bit. Some advice for 1.8 to stay in line with the 1.9 changes:
- Always define an application namespace when using an instance namespace.
- An app shouldn't depend on the project's url configuration, so always use the application namespace in the view name, i.e. reverse('polls:view'), not reverse('author-polls:view').
- A project that uses an app may point to a specific instance namespace of that app when necessary, i.e. on the front page with links to both author-polls and publisher-polls.
- The currently active instance namespace is available as request.resolver_match.namespace.
- You can set request.current_app = request.resolver_match.namespace before rendering templates, and the {% url %} template tag will use the current namespace for urls in the same application namespace.
- You can explicitly pass the current namespace to current_app in reverse() to do the same.
It seems a bit weird that that's not automatic.
That still leaves the question of what Model.get_absolute_url() should do, given that it has no way to get the current app that I can see. Thank you for your very helpful comments though.
It seems a bit weird that that's not automatic.That's what I thought, so it's automatic in 1.9.
That still leaves the question of what Model.get_absolute_url() should do, given that it has no way to get the current app that I can see. Thank you for your very helpful comments though.It can't know the current app. I never use it for anything but the helpful "View on site" link in the admin. I have some plans to revisit this API, but that depends on some other work I'm still finishing.