regiondavid
regiondavid

Reputation: 3

What's the meaning of using patterns in Django URLs?

In my Django project, I find the project urls.py resolve URLs directly

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^test/', include('test.urls')),
]

but I find the app urls.py solution always use

urlpatterns = patterns('',
    url(r'^$', views.index, name='index'),
    url(r'^new$', views.new, name='new'),
)

when I try to change app's urls.py to

urlpatterns = [
    url(r'^$', views.index, name='index'),
    url(r'^new$', views.new, name='new'),
]

or

urlpatterns = patterns('',
    url(r'^$', views.index, name='index'),
)
urlpatterns += patterns('',
    url(r'^new$', views.new, name='new'),
)

also works, so I want to know the meaning of using patterns and which one is better.

Upvotes: 0

Views: 171

Answers (1)

Sayse
Sayse

Reputation: 43320

Patterns is deprecated since 1.8 (and removed in 1.10)

from the 1.8 docs:

Deprecated since version 1.8:

urlpatterns should be a plain list of django.conf.urls.url() instances instead.

Upvotes: 1

Related Questions