Code

Opened 2 years ago

Last modified 19 months ago

#17716 new Bug

include(arg, namespace=None, app_name=None) replace app_name with namespace

Reported by: blackip@… Owned by: nobody
Component: Core (URLs) Version: 1.4-alpha-1
Severity: Normal Keywords: include reverse url
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by aaugustin)

When we register urls - we can specify app_name like this

urlpatterns = patterns('',
    url(r'^inventory/', include('inventory.urls', app_name='inventory')),
    url(r'^cart/', include('cart.urls',app_name='cart')),

Then we can use reverse method or {% url cart:cart %} to generate url.

But it does not work

got NoReverseMatch at /cart/

u'cart' is not a registered namespace
Request Method:	GET
Request URL:	http://localhost:8000/cart/
Django Version:	1.4a1

When I register urls like this

    url(r'^inventory/', include('inventory.urls', namespace='inventory')),
    url(r'^cart/', include('cart.urls',namespace='cart')),

IT DOES WORK !

According to documentation format for urls should be

{% url app_name:view_name %}

but actual format is

{% url namespace:view_name %}

I think this is a bug

The source of bug may be in
file /usr/local/lib/python2.7/site-packages/django/conf/urls/__init__.py
function include(arg, namespace=None, app_name=None)

It returns tuple (urlconf_module, app_name, namespace)

It looks like it should be (urlconf_module, namespace, app_name)

Attachments (0)

Change History (6)

comment:1 Changed 2 years ago by aaugustin

  • Description modified (diff)
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Fixed formatting (please use preview).

comment:2 Changed 2 years ago by aaugustin

  • Triage Stage changed from Unreviewed to Accepted

Reading the URL namespaces docs, it appears that it's invalid to write an include with app_name but without namespace.

Django could check that app_name and namespace are either both None, or both not None, in django.conf.urls.url, making this error is easier to debug. Accepting on this basis.

comment:3 Changed 22 months ago by mtredinnick

We should either make this an error, or make it work. Aymeric has a cunning plan that requires this to work in some sense, so we'll probably go for the latter approach (might not be too hard).

In any case, the ambiguous and non-documented, confusing behaviour is currently unacceptable.

comment:4 Changed 19 months ago by k.znamenskiy@…

I'm new in django and begin learning info about urls, app_name and namspace

It's realized so intricately:
when include

url(r'^anypages1/', include('anypages.urls', app_name='anypages' namespace='anypages1'))
url(r'^anypages2/', include('anypages.urls', app_name='anypages' namespace='anypages2'))

when reverse

reverse('anypages:url_name', args=[myarg], current_app='anypages1') 
reverse('anypages:url_name', args=[myarg], current_app='anypages2') 

now app_name used in viewname as namespace and namespace pass as curreny_app parameter
so so intricately!

may be at least rename parameter current_app to current_namespace? Or any another actions for more consistency...

Sorry for my english:)

comment:5 Changed 19 months ago by abki

  • Cc amirouche.boubekki@… added

comment:6 Changed 19 months ago by abki

  • Cc amirouche.boubekki@… removed

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as new
The owner will be changed from nobody to anonymous. Next status will be 'assigned'
as The resolution will be set. Next status will be 'closed'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.