1👍
Do you mean something like this?
def get_slug(self, name):
slug = self.kwargs[name]
return get_object_or_404(Language, slug=slug)
Can use as language = self.get_slug('slug')
Bear in mind that if kwargs
doesn’t contain name
then it’ll throw an error. To prevent this you could do something like:
slug = self.kwargs.get(name, None)
if slug is not None:
...
Source:stackexchange.com