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

后端 未结 13 2604
误落风尘
误落风尘 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:16

    Inside myapp/urls.py add the following module-level attribute:

    app_name = "polls"
    

    This will set the "application namespace name" for that application. When you use names like "polls:submit" in a reverse, Django will look in two places: application namespaces (set like above), and instance namespaces (set using the namespace= parameter in the "url" function). The latter is important if you have multiple instances of an app for your project, but generally it's the former you want.

    I had this very issue, and setting namespace= into the url() function seemed wrong somehow.

    See this entry of the tutorial: https://docs.djangoproject.com/en/1.9/intro/tutorial03/#namespacing-url-names

    Update: this information is correct for Django 1.9. Prior to 1.9, adding a namespace= attribute to the include is, indeed, the proper way.

提交回复
热议问题