Django 以字符串形式获取当前视图的名称
问题描述:
是否可以以字符串形式获取 Django 视图的名称?我搜索了很多,但找不到答案.
Is it possible to get the name of Django view in string form? I have searched a lot but could not find the answer.
答
以上对我不起作用,但我能够通过在 request
上运行 dir
来找到一些解决方案代码>.
The above did not work for me, but I was able to find some solutions by running dir
on request
.
request.resolver_match.view_name
似乎给了我正确的视图名称.
seems to give me the correct name for the view.