I am currently learning Django. Until now I was working with Django 1.1 but now I am working with Django 2.0. Django 2.0 uses path() instead of url() and I don't quiet understand that.
In Django 1.1 my urls looked like this:
url(r'^about/$', views.AboutView.as_view(), name='about'),
Now with Django 2 it looks like this
path('about/', views.AboutView.as_view(), name='about'),
So far so good but I just don't undertand how I can convert this
url(r'^post/(?P<pk>\d+)$', views.PostDetailView.as_view(),
name='post_detail'),
So that it works with the new version. Just chagning url to path doesn't work, and changing url to re_path doesn't work either. Can someone help me with that Problem?
Thanks in advance
The regular expressions are to be put in different way.
path('post/<int:pk>', views.PostDetailView.as_view(), name='post_detail'),
I just tried and tested this with the same url that you have, in one of my projects and it works. They have made the url more simpler and readable by letting to use the keyword int
there.
This is the new method to do it, Please read the release notes they have clearly mentioned these changes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With