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

无人久伴 提交于 2020-01-03 18:14:52

问题


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 using Django 1.3.


回答1:


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



来源:https://stackoverflow.com/questions/7363291/django-resolverequest-path-app-name-does-not-return-app-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!