Given a uri like /home/
I want to find the view function that this corresponds to, preferably in a form like app.views.home
or just <app_label>.<view_func>
. Is there a function that will give me this?
Excellent! This is what I built out of it:
def response(request, template=None, vars={}):
if template is None:
view_func = resolve(request.META['REQUEST_URI'])[0]
app_label = view_func.__module__.rsplit('.', 1)[1]
view_name = view_func.__name__
template = '%s.html' % os.path.join(app_label, view_name)
return render_to_response(template, vars, context_instance=RequestContext(request))
Now you can just call return response(request)
at the end of your view funcs and it will automatically load up app/view.html
as the template and pass in the request context.