Opened 11 years ago

Closed 11 years ago

#21369 closed Bug (worksforme)

get_absolute_url() Reverse Example Doesn't Work

Reported by: tabdon@… Owned by: nobody
Component: Documentation Version: 1.5
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Example on this page shows the following, which didn't work for me.

def get_absolute_url(self):
    return reverse('people.views.details', args=[str(self.id)])

Instead I was only able to get this to work:

def get_absolute_url(self):
    return reverse('people.views.details', kwargs={'id': self.id})

Change History (1)

comment:1 by Baptiste Mispelon, 11 years ago

Resolution: worksforme
Status: newclosed

Hi,

It seems to be working for me, using the following code (in an freshly created app called people):

# models.py
from django.db import models
from django.core.urlresolvers import reverse

class Person(models.Model):
    first_name = models.CharField(max_length=50)
    last_name = models.CharField(max_length=50)

    def get_absolute_url(self):
        return reverse('people.views.details', args=[str(self.id)])

# admin.py
from django.contrib import admin

from.models import Person

admin.site.register(Person)

# views.py
from django.http import HttpResponse

def details(request, id):
    return HttpResponse("It's working.")

In my main urls.py, I also have the following line:

url(r'^p/(?P<id>\d+)$', 'people.views.details'),

With this, I can use the "view on site" feature of the admin (which makes use of get_absolute_url) and it works as expected.

I'm therefore closing this ticket as worksforme.
If you have can provide steps to reproduce your issue or a more detailed error message, please reopen it.

Thanks.

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