Django:resolve(request.path).app_name不返回应用程序名称 [英] Django: resolve(request.path).app_name does not return app name
本文介绍了Django:resolve(request.path).app_name不返回应用程序名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从视图或模板访问当前的应用程序名称。
I'm trying to access the current app name from a view or template.
在其他SO答案中如何使用python在django中获取应用程序名称和如何获取Django中的当前应用程序我发现 resolve(request.path).app_name
应该返回当前的应用程序名称。但是在我的情况下,它会返回无。
In other SO answers How to get an app name using python in django and How to get current application in Django I found that resolve(request.path).app_name
should return the current app name. But in my case it alwas returns "None".
我正在使用Django 1.3。
I'm using Django 1.3.
推荐答案
为了工作,您必须在包含您的网址时传递 app_name
参数:
For that to work, you have to pass a app_name
parameter when including your urls:
#urls.py
urlpatterns = patterns('',
(r'^manufacturers/', include('manufacturers.urls', app_name='manufacturers')),
)
#shell output
In [1]: resolve('/manufacturers/my_manufacturers/').app_name
Out[1]: 'manufacturers'
更多信息:定义URL命名空间
这篇关于Django:resolve(request.path).app_name不返回应用程序名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文