Django Error u“'polls” is not a registered namespace

后端 未结 13 2610
误落风尘
误落风尘 2021-01-31 07:41

Yesterday I was working on my first app using this tutorial. It\'s a Poll and Choice app. The first page displays the question and when you click on the question it\'s suppose t

13条回答
  •  孤街浪徒
    2021-01-31 08:04

    The answer is to add namespaces to your root URLconf. In the mysite/urls.py file (the project’s urls.py, not the application’s), go ahead and change it to include namespacing:

    urlpatterns = patterns('',
    url(r'^polls/', include('polls.urls', namespace="polls")),
    url(r'^admin/', include(admin.site.urls)),
    )
    

    Furthermore, in part 3 of the tutorial Namespacing URL names the use of app_name is mentioned as the accepted way for adding the polls namespace. You can add the line for this in your polls/urls.py as follows:

    app_name = 'polls'
    urlpatterns = [
        ...
    ]
    

提交回复
热议问题