How to find which view is allowed from a URL in the presence of decorators

For debugging purposes, I would like to quickly (for example, in the manage.py shell) see which view will be called up as a result of requesting a specific URL.
I know that this is what django.core.urlresolvers.resolve does, but when it has a decorator in the view function, it will return that decorator.
Example:

>>>django.core.urlresolvers.resolve('/edit_settings/'))
(Allow, (), {})

... where Allow is a decorator, not its decoration.

How can I find a view without manually inspecting urls.py files?

+3
source share
1 answer

This is not my area of ​​expertise, but it can help.

You can explore Allowto find out which object it adorns.

>>>from django.core.urlresolvers import resolve
>>>func, args, kwargs=resolve('/edit_settings/')
>>>func
Allow

>>>func.func_name

.

, :

>>>def decorator(func):
...    def wrapped(*args,**kwargs):
...        return func(*args,**kwargs)
...    wrapped.__doc__ = "Wrapped function: %s" %func.__name__
...    return wrapped

>>>def add(a,b):
...    return(a,b)

>>>decorated_add=decorator(add)

, decorated_add.func_name, wrapped. add. doc wrapped, :

>>>decorated_add.func_name
wrapped
>>>decorated_add.__doc__
'Wrapped function: add'

, , Allow, , , .

+1

Source: https://habr.com/ru/post/1718539/


All Articles