Home > OS >  Django parameters in URL
Django parameters in URL

Time:08-13

I am trying to write a delete function for my CRUD API with Python Rest Framework. In the delete I want to delete a specific item in the database, and I want it to be passed via link parameter like so: path/to/link/to/delete/post3.

I did that in the url file:

path("link/<int:link_pk>/", views.LinkView.as_view(),
         name="link_integration")

Then, in the ApiView that is the code:

    @log_request_decorator
    def delete(self, request: Request, link_pk: int, **kwargs) -> JsonResponse:
        do_stuff()
        #print(social_integration_pk)
        return JsonResponse({}, status=204)

And here is the code of the test that I am using to test it:

link = "link/1/"
factory = APIRequestFactory()
request = factory.delete(link)
view = LinkView.as_view()
---forced auth---
response = view(request)

And I get this as output:

TypeError: delete() missing 1 required positional argument: 'link_pk'

Do someone know how to fix that? I need to have that parameter in order to do what I am supposed to. Maybe is something silly, but I don't know. If you can, please help me. Thank you

CodePudding user response:

I have a suspicion that it could be one of two things:

  1. response = view(request) should be response = view(request, link_id=1) OR
  2. view = LinkView.as_view() should be view = LinkView.as_view({'delete':'delete'})
  • Related