gpt4 book ai didi

django - 从请求uri获取 View 功能?

转载 作者:行者123 更新时间:2023-12-03 13:45:12 26 4
gpt4 key购买 nike

给定一个像/home/这样的uri,我想找到它对应的 View 函数,最好是像app.views.home<app_label>.<view_func>这样的形式。有功能可以给我这个吗?

最佳答案

您可以使用django提供的resolve方法来获取该功能。您可以使用返回的函数的__module__属性来获取应用标签。这将返回类似project.app.views的字符串。所以像这样:

from django.urls import resolve

myfunc, myargs, mykwargs = resolve("/hello_world/")
mymodule = myfunc.__module__

关于django - 从请求uri获取 View 功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3081327/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com