Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get view function from request uri?

Tags:

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?

like image 398
mpen Avatar asked Jun 20 '10 23:06

mpen


1 Answers

You can use the resolve method provided by django to get the function. You can use the __module__ attribute of the function returned to get the app label. This will return a string like project.app.views. So something like this:

from django.urls import resolve  myfunc, myargs, mykwargs = resolve("/hello_world/") mymodule = myfunc.__module__ 
like image 88
KillianDS Avatar answered Oct 03 '22 06:10

KillianDS