ArminMz
ArminMz

Reputation: 345

How can I set query params in a url of django rest framework?

I have an API that i need to remove something from cache of Redis So I build a view and sync it to a url but I keep getting HTTP_404 (not found).

class ExpireRoom(APIView):
    permission_classes = (IsAuthenticated, )

    def delete(self, request, format=None):
        room_manager = RoomManager()
        room_identifier = self.kwargs['room_identifier']
        is_success = room_manager.delete(room_identifier)
        if is_success:
            return Response(status=status.HTTP_200_OK)
        else:
            return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR)

Here's my url in urls.py:

urlpatterns = [
    url(r'^expire-room/(?P<room_identifier>\w+)/$', 
        ExpireRoom.as_view(),
        name='core_ExpireRoom_deletingRoom')
]

Upvotes: 1

Views: 3628

Answers (1)

dirkgroten
dirkgroten

Reputation: 20702

Not sure what URL you are requesting, but your question's title suggests you're passing query parameters.

Query parameters aren't part of the URL path, i.e. you don't need to pre-define them in the url patters. If you have a pattern for /expire-room/ then /expire-room/?myparam=hello&someotherparam=world will just work and pass myparam and someotherparam to the request.GET dictionary.

The URL pattern you defined will only match URLs starting with /expire-room/some-room/ where some-room is any string.

Upvotes: 4

Related Questions