reverse() argument after ** must be a mapping reverse() argument after ** must be a mapping django django

reverse() argument after ** must be a mapping


I try to answer, since I had the same problem but didn't find an answer online.

I think the origin of this problem is a wrong get_absolute_url(...) method. For example, if you write it like this:

@models.permalinkdef get_absolute_url(self):    return reverse('my_named_url', kwargs={ "pk": self.pk })

Then it raises the exception reverse() argument after ** must be a mapping, not str. Fix it removing the @models.permalink decorator, as follows:

def get_absolute_url(self):    return reverse('my_named_url', kwargs={ "pk": self.pk })

or alternatively keep the decorator and modify the body, as follows:

@models.permalinkdef get_absolute_url(self):    return ('my_named_url', (), { "pk": self.pk })

I think that the latter is deprecated, though.