我最近将我的 django 项目从 3.14 升级到 4.0,django.urls.resolve 函数似乎损坏了。 Resolve 总是返回 app_name.views.view 而不是 app_name.views.actual_function_name。
这是我的代码-
path = request.path
match = resolve(path)
view_name = match.view_name
在上述代码之后,“view_name”变量始终是“view”,与 url 无关。任何帮助表示赞赏。谢谢你的时间。
附言如果有任何其他方式,我可以在不使用 resolve 的情况下从 url 中找到函数,也请告诉我。
尝试从您的resolve(path)
调用func
from django.urls import resolve
path = request.path
match = resolve(path)
view_function = match.func