Задать вопрос

Тел: +7 965 3737 888





Decorating URL includes

Apply a decorator to every urlpattern and URLconf module returned by Django's include() method . This allows you use a decorator on any number of views without having to decorate each one individually.

The use case here is wrapping all of the Django Admin with a superuser decorator. This is code that's better left alone where we can't actually go in and decorate the Admin views and urlpatterns manually. It's also almost guaranteed the Admin will include() other URL files. So the added bonus is all the INSTALLED_APPS that have their admin.py files registered by admin.autodiscover() will be decorated automatically as well.

This snippet is greatly inspired by @miracle2k's excellent #532. In the comments there @timbroder offers a modification to decorate includes but I think this is cleaner, simpler code and not subject to changes in the Django base code driving _get_url_patterns().

Вопрос полезен? Да0/Нет0

Ответы (1):

Ответ полезен? Да0/Нет0

awesome, thanks!