Tutorial 3: Class-based Views

29 views
Skip to first unread message

adam.d....@gmail.com

unread,
Oct 15, 2016, 7:35:03 PM10/15/16
to Django REST framework
I spent the better part of the day going through this example and found what I think is an oversight that might be worth updating. There is no mention that when you switch to generic class-based views that the url patterns needs to update from  url(r'^snippets/(?P<id>[0-9]+)/$', views.SnippetDetail.as_view()), TO  url(r'^snippets/(?P<pk>[0-9]+)/$', views.SnippetDetail.as_view()).I hope this can help someone.

joaofiguei...@gmail.com

unread,
Oct 16, 2016, 4:42:16 PM10/16/16
to Django REST framework


On Sunday, October 16, 2016 at 12:35:03 AM UTC+1, adam.d....@gmail.com wrote:
I spent the better part of the day going through this example and found what I think is an oversight that might be worth updating. There is no mention that when you switch to generic class-based views that the url patterns needs to update from  url(r'^snippets/(?P<id>[0-9]+)/$', views.SnippetDetail.as_view()), TO  url(r'^snippets/(?P<pk>[0-9]+)/$', views.SnippetDetail.as_view()).I hope this can help someone.

As an alternative you can add a field lookup_field to the SnippetDetail view class with the value "id"
Reply all
Reply to author
Forward
0 new messages