[Answered ]-Is it possible to pass the foreign key id in Django rest-framework URL?

1👍

After changing the URL in regex format, my issue was solved. Instead of this,

router.register('user/<int:user_id>/profile', ProfileViewSet, 'profile')

I wrote this,

router.register(r'user/(?P<user_id>\d+)/profile', ProfileViewSet, 'profile')

0👍

Change this line

router.register('user/<int:user_id>/profile', ProfileViewSet, 'intensity_classes')

Use this

router.register(r'users', ProfileViewSet, basename='user')

Then for list view

http://127.0.0.1:8000/users/ -> List of profiles

For detail view

http://127.0.0.1:8000/users/13
->here 13 is the profile id, you can update, delete the Profile instance

Leave a comment