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')

On Sunday, December 6, 2015 at 3:29:29 AM UTC+3, Jon Ribbens wrote:
>
> I'm using Django 1.8. If I'm writing an app, and I want to add 
> get_absolute_url() to a model, the question is: what do I put for the first 
> argument to 'reverse'?
>
> The documentation at 
> https://docs.djangoproject.com/en/1.8/topics/http/urls/#url-namespaces 
> implies that I need to know two things: the instance name, and the app 
> name. The problem is that get_absolute_url() knows neither of these.
>
> Imagine my app has a urlpattern like:
>
>     url(r'^view/(\d+)$', views.view, name="view")
>
>
> I could just say reverse("view", self.id) but what if another app has a 
> view called 'view'? What if my app is instanced twice - i.e. as shown in 
> the docs:
>
>     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')),
>
>
> ?
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/54f24891-e6ba-41d4-b8fc-b8914729f65a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to