New way to use URL dispatchers?

35 views
Skip to first unread message

Aliane Abdelouahab

unread,
Oct 24, 2014, 10:11:40 PM10/24/14
to django...@googlegroups.com
Hi,
in the docs, i only see the 'list' way, so why Django 1.7 dont generate the url by the new way and still use the old way?
because i found:

Deprecated since version 1.8: urlpatterns should be a plain list of django.conf.urls.url() instances instead.


as the example here:
from django.conf.urls import url

from . import views

urlpatterns = [
    url(r'^articles/2003/$', views.special_case_2003),
    url(r'^articles/([0-9]{4})/$', views.year_archive),
    url(r'^articles/([0-9]{4})/([0-9]{2})/$', views.month_archive),
    url(r'^articles/([0-9]{4})/([0-9]{2})/([0-9]+)/$', views.article_detail),
]
so the urls.py should be like:

from django.conf.urls import patterns, include, url
from django.contrib import admin

urlpatterns = [
    # Examples:
    # url(r'^$', 'First.views.home', name='home'),
    # url(r'^blog/', include('blog.urls')),

    url(r'^admin/', include(admin.site.urls)),
]

Russell Keith-Magee

unread,
Oct 24, 2014, 10:39:33 PM10/24/14
to Django Users

Hi Aliane,

You're getting tripped up by the version number of your documentation, combined with an understanding of the way we handle deprecations.

When the documentation says "Deprecated since version 1.8", it means "Version 1.8 introduced this change". Versions 1.7 and earlier *doesn't* include the change. 

However, version 1.8 hasn't been released yet. The documentation you referenced is the *development* documentation - that is, it's the documentation for the version of Django that is currently in development (i.e., 1.8). There's a yellow banner at the top of the page to warn you about this.

When it is released, Django 1.8 will include support for the new preferred format for URLpatterns. Django 1.7 doesn't support this new format, and the documentation for version 1.7:


doesn't mention the new format. 

Hope that helps!

Yours,
Russ Magee %-)


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/253da748-e5a3-45f3-8195-bbd08754e844%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Aliane Abdelouahab

unread,
Oct 24, 2014, 10:59:22 PM10/24/14
to django...@googlegroups.com
Ah, thank you!
i thought that it was introduced long ago (something like 1.6) and is in test period, so it will be officially deprecated after 1.8, and the 1.7 would be the 'hybrid' version that will allow both of them.

so now, i can stick with the old one, thank you :)

Carl Meyer

unread,
Oct 25, 2014, 4:04:49 PM10/25/14
to django...@googlegroups.com

On Oct 24, 2014, at 8:37 PM, Russell Keith-Magee <rus...@keith-magee.com> wrote:

When it is released, Django 1.8 will include support for the new preferred format for URLpatterns. Django 1.7 doesn't support this new format, and the documentation for version 1.7:


doesn't mention the new format. 

Small clarification: the “new” way (urlpatterns just a list of urls) actually works just fine in 1.7, 1.6, and earlier versions of Django too (as long as you use the `url(…)` function to define each url, and import your views rather than referencing them as strings). So you can switch to it right now, regardless of what Django version you are using.

The 1.7 docs still use the `patterns(…)` function (which is deprecated starting in 1.8) simply in order to maintain compatibility with the output of 1.7’s startproject command.

Carl

Aliane Abdelouahab

unread,
Oct 25, 2014, 5:35:47 PM10/25/14
to django...@googlegroups.com
ah! thank you, because this is the 'cleanest' way, espetially for a beginner.
thank you :)
Reply all
Reply to author
Forward
0 new messages