djangolearner
djangolearner

Reputation: 118

Difference between named urls in Django?

What is the difference between these two named urls in Django?

 re_path('articles/(?P<year>[0-9]{4})/', views.year_archive),
 path('articles/<int:year>/', views.year_archive),

They appear to do the same?

Upvotes: 2

Views: 319

Answers (1)

Bakhrom Rakhmonov
Bakhrom Rakhmonov

Reputation: 702

  • path is a new style of url defining added in django 2.0 which has its own markup
  • re_path is a more advanced method that requires you to write your own regex for the url. This is the method all url patterns used in django <= 1.11

if you using old style libraries in your django app you can use re_path instead of url of old version and if you creating new urls you can use either

Upvotes: 3

Related Questions