My environment:
- django 1.11.3
- python 3.6.2 64 bit
- Windows 7 SP1 64bit Pro German
This is just what I did:
- I created a djproject with {{{django-admin startproject djproject}}}
- then I added "djproject" to INSTALLED_APPS
- now I added the following files:
- djproject/views.py
- djproject/Templates/djproject/index.html
- in djproject/urls.py I add the module veriable:
{{{app_name = "djproject"}}}
my index.html looks like:
{{{
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<p> the title is {{title}}</p>
<p> the url of this page is: {% url 'index' %}
</body>
</html>
}}}
which works!
But if modify it to use namespace 'djproject' like this:
{{{
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<p> the title is {{title}}</p>
<p> the url of this page is: {% url 'djproject:index' %}
</body>
</html>
}}}
I get an Exception:
{{{django.urls.exceptions.NoReverseMatch: 'djproject' is not a
registered namespace}}}
The whole project is attached. To reproduce:
- run: {{{manage.py runserver}}}
- browse to: {{{http://localhost:8000}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/28413>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* Attachment "djproject.zip" added.
project file to reproduce the error
* cc: Marten Kenbeek (added)
* component: Uncategorized => Core (URLs)
* type: Uncategorized => Bug
Comment:
I think the issue is that `app_name` isn't supported in `ROOT_URLCONF`.
I'm not sure if it makes sense to support that.
--
Ticket URL: <https://code.djangoproject.com/ticket/28413#comment:1>
* status: new => closed
* resolution: => invalid
Comment:
Replying to [comment:1 Tim Graham]:
> I think the issue is that `app_name` isn't supported in `ROOT_URLCONF`.
I'm not sure if it makes sense to support that.
That's right, `app_name` is only supported in included urlconfs.
URL namespaces are designed to prevent naming conflicts between included
urlconfs, and to allow the deployment of more than one instance of a
specific urlconf. Adding a namespace to the root urlconf only has the
cosmetic effect that you need to prepend ''every'' viewname with that
namespace when reversing, it does not help with naming conflicts or
multiple deployments. I don't think it makes sense to support this.
I'm closing this as invalid as it is certainly not a bug.
--
Ticket URL: <https://code.djangoproject.com/ticket/28413#comment:2>
* status: closed => new
* resolution: invalid =>
Comment:
OK, now its clear.
Could you ad a small piece of information in:
https://docs.djangoproject.com/en/1.11/ref/applications/#projects-and-
applications
in the part:
"There’s no restriction that a project package can’t also be considered an
application and have models, etc. (which would require adding it to
INSTALLED_APPS)"
Adding that Url namespaces will not work and in ROOT_URLCONF should not be
used and are not necessary? (or similar)
I ask for this because the text starts with: **There’s no restriction...**
but in this case we have a restriction.
Thanks.
--
Ticket URL: <https://code.djangoproject.com/ticket/28413#comment:3>
Comment (by Tim Graham):
I'm not sure this is a common pitfall -- as Marteen said, why would
somebody try to put a namespace in a `ROOT_URLCONF`? Also, there isn't a
restriction that you have to put your `ROOT_URLCONF` in a "project
package" so a note there may be not be most helpful. Rather than a
documentation note, it would probably be more helpful to add a system
check to error about the mistake but is it worth it? I haven't come across
anyone else making the mistake.
--
Ticket URL: <https://code.djangoproject.com/ticket/28413#comment:4>
* status: new => closed
* resolution: => invalid
Comment:
[https://github.com/django/django/pull/8804 PR] to document that
namespaces aren't supported in ROOT_URLCONF.
--
Ticket URL: <https://code.djangoproject.com/ticket/28413#comment:5>