[Django] #28413: URL namespaces do not work if the django project is used as django app

14 views
Skip to first unread message

Django

unread,
Jul 19, 2017, 7:10:25 AM7/19/17
to django-...@googlegroups.com
#28413: URL namespaces do not work if the django project is used as django app
-----------------------------------------+------------------------
Reporter: stephanm | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.11
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
In https://docs.djangoproject.com/en/1.11/ref/applications/#projects-and-
applications
there is written:
"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)"

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.

Django

unread,
Jul 19, 2017, 7:11:14 AM7/19/17
to django-...@googlegroups.com
#28413: URL namespaces do not work if the django project is used as django app
-------------------------------+--------------------------------------

Reporter: stephanm | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.11
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by stephanm):

* Attachment "djproject.zip" added.

project file to reproduce the error

Django

unread,
Jul 19, 2017, 9:29:16 AM7/19/17
to django-...@googlegroups.com
#28413: app_name doesn't work in ROOT_URLCONF
-----------------------------+--------------------------------------
Reporter: stephanm | Owner: nobody
Type: Bug | Status: new
Component: Core (URLs) | Version: 1.11
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+--------------------------------------
Changes (by Tim Graham):

* 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>

Django

unread,
Jul 19, 2017, 9:59:00 AM7/19/17
to django-...@googlegroups.com
#28413: app_name doesn't work in ROOT_URLCONF
-----------------------------+--------------------------------------
Reporter: stephanm | Owner: nobody
Type: Bug | Status: closed

Component: Core (URLs) | Version: 1.11
Severity: Normal | Resolution: invalid

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+--------------------------------------
Changes (by Marten Kenbeek):

* 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>

Django

unread,
Jul 20, 2017, 7:43:00 AM7/20/17
to django-...@googlegroups.com
#28413: app_name doesn't work in ROOT_URLCONF
-----------------------------+--------------------------------------
Reporter: stephanm | Owner: nobody
Type: Bug | Status: new

Component: Core (URLs) | Version: 1.11
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+--------------------------------------
Changes (by stephanm):

* 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>

Django

unread,
Jul 20, 2017, 1:21:06 PM7/20/17
to django-...@googlegroups.com
#28413: app_name doesn't work in ROOT_URLCONF
-----------------------------+--------------------------------------
Reporter: stephanm | Owner: nobody

Type: Bug | Status: new
Component: Core (URLs) | Version: 1.11
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+--------------------------------------

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>

Django

unread,
Jul 24, 2017, 6:38:44 PM7/24/17
to django-...@googlegroups.com
#28413: app_name doesn't work in ROOT_URLCONF
-----------------------------+--------------------------------------
Reporter: stephanm | Owner: nobody
Type: Bug | Status: closed

Component: Core (URLs) | Version: 1.11
Severity: Normal | Resolution: invalid

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+--------------------------------------
Changes (by Tim Graham):

* 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>

Reply all
Reply to author
Forward
0 new messages