0

My urls.py looks like this:

urlpatterns = [
    path('',views.index, name='index'),
    path('entry/(<int:pk>)' , views.details,name='details'),
    path('admin/', admin.site.urls),
]

but when i try to run it i get error as cannot find path.

Attempt 1 :

I tried to use url instead but I am not sure how to use second line into url. This does not seems to work:

urlpatterns = [
    url(r'^$',views.index, name='index'),
    url(r'^entry/(?P<pk>\d+)/' , views.details,name='details'),
    url(r'^admin/', admin.site.urls),
]
Ashish Kumar
  • 61
  • 1
  • 7

2 Answers2

1

I wanted to comment on Monhammand's answer. But, I couldn't do that, because I needed to have at least 50 reputations. So, I submit this as an answer.

If you would like to use regular expressions in Django 2.X, you can use re_path().

https://docs.djangoproject.com/en/2.0/ref/urls/#re-path

urlpatterns = [
  re_path(r'^$',views.index, name='index'),
  re_path(r'^entry/(?P<pk>\d+)/$' , views.details,name='details'),
  re_path(r'^admin/', admin.site.urls),
]
Lim
  • 753
  • 14
  • 31
0

If you are using django 2.x, do like this:

urlpatterns = [
    path('',views.index, name='index'),
    path('entry/<int:pk>/' , views.details,name='details'),
    path('admin/', admin.site.urls),
]

If you are using django 1.x, do like this:

urlpatterns = [
    url(r'^$',views.index, name='index'),
    url(r'^entry/(?P<pk>\d+)/$' , views.details,name='details'),
    url(r'^admin/', admin.site.urls),
]

/ and $ are important

Ali
  • 2,541
  • 2
  • 17
  • 31