Reputation: 57138
I can get the view function from request.path
:
from django.core.urlresolvers import resolve
view_func, _args, _kwargs = resolve(request.path)
However, I need something more. I need to take a list of view names, like ['edit_foo', 'delete_foo']
, and find out if the current URL is for one of those.
I've come up with a couple ideas using some internals from django.core.urlresolvers
, but I want something that will be efficient and somewhat correct (ie, not hacky, ideally documented).
Upvotes: 2
Views: 1014
Reputation: 57138
After writing that long question, I figured it out :/ (posting for whoever else runs into this, by chance). It's quite simple:
>>> resolve(request.path).url_name
'edit_foo'
I must have been mistaken about the resolve
function's usefulness, which is vast.
Upvotes: 5