如何在django中使用python获取应用程序名称 [英] How to get an app name using python in django
本文介绍了如何在django中使用python获取应用程序名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果您在视图中并希望使用Python检索应用程序名称(应用程序名称将用于进一步的逻辑),您将如何处理?
If you are in the view and want to retrieve the app name using Python ( the app name will be used for further logic ), how would you do it ?
推荐答案
你可以这样做:
from django.core.urlresolvers import resolve
....
resolve(request.path).app_name
请参阅如何获取Django中的当前应用程序和< a href =http://docs.djangoproject.com/en/dev/topics/http/urls/#resolve =nofollow noreferrer> resolve()
编辑:现在可以使用 request.resolver_match.app_name ,这避免了第二次解析并避免导入。这样做:
You can now use request.resolver_match.app_name which avoids resolving a second time and avoids an import. Do it this way:
request.resolver_match.app_name
这篇关于如何在django中使用python获取应用程序名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文