[Fixed]-Reverse() argument after ** must be a mapping

19๐Ÿ‘

โœ…

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.permalink
def 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.permalink
def get_absolute_url(self):
    return ('my_named_url', (), { "pk": self.pk })

I think that the latter is deprecated, though.

๐Ÿ‘คFSp

2๐Ÿ‘

Naughty comma

return redirect(reverse_lazy('team-detail', kwargs={'pk', team.pk}))

it should be

return redirect(reverse_lazy('team-detail', kwargs={'pk': team.pk}))
๐Ÿ‘คWeilory

Leave a comment