Skip to content

Instantly share code, notes, and snippets.

@schinckel
Created March 27, 2014 23:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schinckel/9821292 to your computer and use it in GitHub Desktop.
Save schinckel/9821292 to your computer and use it in GitHub Desktop.
from django.views.generic.base import View
def get_class(func):
if not getattr(func, 'func_closure', None):
return
for closure in func.func_closure:
contents = closure.cell_contents
if not contents:
continue
if getattr(contents, '__bases__', None) and issubclass(contents, View):
return contents
result = get_class(contents)
if result:
return result
from django.core.urlresolvers import resolve
view = resolve('/path/to/url')
get_class(view.func)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment