如何在 Django 中使用 python 获取应用程序名称 [英] How to get an app name using python in django

查看:26
本文介绍了如何在 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 中获取当前应用程序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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆