开发者

Django: resolve(request.path).app_name does not return app name

开发者 https://www.devze.com 2023-04-03 15:45 出处:网络
I\'m trying to access the current app name from a view or template. 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

I'm trying to access the current app name from a view or template.

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".

I'm us开发者_如何学Pythoning Django 1.3.


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'

More info: Defining URL namespaces

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号