Kadiem Alqazzaz
Kadiem Alqazzaz

Reputation: 663

Django pass parameters

I'm trying to pass pk key

urlpatterns = [
path('api/products', ProductAPI.as_view()),
path('api-admin/products/', ProductAdminAPI.as_view()),
url(r'^api-admin/products/(?P<pk>[0-9]\d+)', ProductAdminAPI.as_view()),
]

with this URL localhost:8000/api-admin/products/3/

but I'm getting 404

Upvotes: 0

Views: 40

Answers (2)

E_K
E_K

Reputation: 2249

Replacing url(r'^api-admin/products/(?P<pk>[0-9]\d+)', ProductAdminAPI.as_view()), with path('api-admin/products/<int:pk>', ProductAdminAPI.as_view()) Will also get the job done.

Upvotes: 1

dirkgroten
dirkgroten

Reputation: 20702

Your expression (?P<pk>[0-9]\d+) is wrong. You need at least 2 digits to match the expression, since you first ask a character [0-9] and then a digit \d.

Remove either [0-9] or \d.

Upvotes: 2

Related Questions