[Answer]-NoReverseMatch after upgrading to Django 1.6 from 1.4

1👍

This doesn’t look like a problem specific to Django 1.6 or class based views. The problem is that the get_absolute_url method doesn’t match the URL pattern.

Firstly, wrapping the variable in quotes is definitely incorrect. Django treats it as a string, your browser treats it as a relative link, and posts the form to the wrong URL.

The project_url URL pattern has four keyword arguments but your get_absolute_url method only specifies slug, which isn’t one of those arguments. I would expect your get_absolute_url method to look something like:

@permalink
def get_absolute_url(self):
    return  ('project_url', (), {'teamslug': self.teamslug,
                                 'projectslug': self.projectslug,
                                 'projectid': self.projectid,
                                 'teamid ': self.teamid,
    })

Note that the docs recommend that you use reverse instead of the permalink decorator.

from django.core.urlresolvers import reverse

def get_absolute_url(self):
    return  reverse('project_url', kwargs={'teamslug': self.teamslug,
                                           'projectslug': self.projectslug,
                                           'projectid': self.projectid,
                                           'teamid ': self.teamid,
    })

Leave a comment