How to do reverse URL search in Django namespaced reusable application

后端 未结 3 1319
不思量自难忘°
不思量自难忘° 2021-01-31 17:37

Consider that I include namespaced reusable application:

urlpatterns = patterns(\'\',
    # ella urls
    url(\'^ella/\', include(\'ella.core.urls\', namespace=\         


        
3条回答
  •  不知归路
    2021-01-31 18:21

    Since you have name-spaced url configuration, you need to mention namespace:view-name pattern in order to reverse it properly (especially from view).

    But, if you want to avoid this, you may also pass namespace/appname as current_app parameter. There are multiple ways to specify current_app when you are in template. But if you are in view, you need to hard-code as you did, or pass to current_app parameter

    url = reverse('object_detail', 
                  kwargs={'foo':'bar'}, 
                  current_app=app_name_or_name_space)
    

    refer: http://docs.djangoproject.com/en/dev/topics/http/urls/#reverse

提交回复
热议问题