Why is django no longer recommending the permalink decorator?

I read the django dev documentation. It states here that the permalink decorator is no longer recommended, use reverse inside your get_absolute_url method to create the full URL for the model instance (scroll down a bit and check the warning window).

I think this violates DRY, that we should use the reverse every time we need it. So what's wrong with using permalink? Why is this no longer recommended?

+4
source share
1 answer

In current versions of django, the decorator literally calls the reverse function, which the documentation recommends anyway. The reason, apparently, is that the decorator is not needed now that we have reverse() . Using reverse looks better than returning a name, tuple, and dictionary. Instead, you use args and kwargs, the idiomatic python.

And this is a ticket that discussed refusing a decorator for API simplicity. Instead of raising warnings and updating code bases for users, they decided to simply put a warning in the documents.

The permalink decorator should be deprecated and ultimately removed. It was introduced to solve the problem of having hard URLs in get_absolute_url. However, this violates one of the basic rules of good decorators in that, due to the fact that the function signature changes to cope with the fact of its design. In addition, it does not provide any useful functions when using the reverse () function directly inside the body of get_absolute_url.

+10
source

All Articles