Opened 7 years ago

Closed 7 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


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(])

Instead I was only able to get this to work:

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

Change History (1)

comment:1 Changed 7 years ago by Baptiste Mispelon

Resolution: worksforme
Status: newclosed


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

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(])

from django.contrib import admin

from.models import Person

from django.http import HttpResponse

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

In my main, 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.


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