gpt4 book ai didi

python - 如何在 View 中检查 Django url 的名称

转载 作者:太空宇宙 更新时间:2023-11-04 05:01:57 25 4
gpt4 key购买 nike

说这是我的网址:

url(r'^$', mainApp_views.homepage),

是否可以在 View 和中间件中检查此 text = "mainApp_views.homepage"?

提前致谢

最佳答案

你想要类似的东西

from django.urls import resolve


def your_view(request):
# resolve the url from the path
url_name = resolve(request.path).url_name

您可能也想将名称添加到您的网址 name='home'

关于python - 如何在 View 中检查 Django url 的名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45498492/

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