Django: formats of urlpatterns in urls.py -


i noticed in django there 2 formats of urlpatterns in file urls.py:

urlpatterns = [     url(...),     url(...), ] 

and

urlpatterns = pattern('',     url(...),     url(...), ) 

the first list of url instances, , second invokes pattern module empty string , number of url instances parameters.

  1. what difference between two?
  2. what purpose of empty string in second format?
  3. which 1 recommended use?

in django 1.8+, urlpatterns should list of url()s. new syntax works in 1.7 well.

urlpatterns = [     url(...),     url(...), ] 

the old syntax using pattern is deprecated in django 1.8, , removed in django 1.10.

urlpatterns = pattern('',     url(...),     url(...), ) 

with old syntax, provide prefix. example given in docs

urlpatterns = patterns('news.views',     url(r'^articles/([0-9]{4})/$', 'year_archive'),     url(r'^articles/([0-9]{4})/([0-9]{2})/$', 'month_archive'),     url(r'^articles/([0-9]{4})/([0-9]{2})/([0-9]+)/$', 'article_detail'), ) 

however, using strings arguments view deprecated well, , should provide callable instead.


Comments