Reputation: 1479
After creating and checking I am running a Python 3.6.1 virtual environment and have Django 3.0.6 installed, I created a project. Within this project the urls.py
file is as shown:
from django.conf.urls import url
from django.contrib import admin
urlpatterns = [
url(r'^admin/', admin.site.urls),
]
However, the Django 3 documentation says the following:
"urlpatterns
should be a sequence of path()
and/or re_path()
instances."(https://docs.djangoproject.com/en/3.0/topics/http/urls/#syntax-of-the-urlpatterns-variable)
If this is the case why does it not generate as path('admin/', admin.site.urls)
?
Can anyone explain this? From my understanding the url()
function is outdated/will be depreciated, but it seems Django is baking it into the project. I believe I am supposed to be using path()
but I am not sure.
Upvotes: 0
Views: 229
Reputation: 15738
path()
is a new way of generating paths that does not involve regex and it is a bit more readable
path('blog/page<int:num>/', views.page),
re_path()
is an old regex style ( prior to django 2.0 only way to define urlconf entries it has also alias url()
)
re_path(r'^blog/(?P<page>[0-9]*)/$', views.page)
Upvotes: 1