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?
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__
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With