Reputation: 1752
I'm using Django 1.7 and Django REST Framework 2.4.3. I have an endpoint that looks like /items/{pk}/notify
, which works beautifully using UpdateAPIView
. I'm trying to pass multiple query parameters to this URL, but I can only seem to get the first parameter. Any subsequent parameters in the URL are committed. I searched around and found that Django has a QueryDict
, which I then proceeded to use lists
to get all values. Unfortunately, this didn't work.
Here is what I have -
class Notify(generics.UpdateAPIView):
queryset = Item.objects.all()
serializer_class = ItemSerializer
def update(request, *args, **kwargs):
print('request: %s', request)
print('args: %s' % args)
print('kwargs: %s' % kwargs)
return Response(data='123')
I'm testing by doing curl -X PATCH 127.0.0.1:8000/items/notify/?ticket_no=123&foo=bar
. Strange thing is that the local Django server isn't logging the full URL. I only see [02/Oct/2014 08:52:03] "PATCH /items/1234/notify/?ticket_no=123 HTTP/1.1" 200 5
.
How can I access all URL parameters?
Upvotes: 1
Views: 832
Reputation: 309009
This isn't a problem with Django, it's an issue with your curl command. You need to put the url in quotes, because &
is a metacharacter that is treated specially by the shell.
curl -X PATCH '127.0.0.1:8000/items/notify/?ticket_no=123&foo=bar'
Without the quotes, &
tells the shell to run the command in the background, and move on to the next command. So the shell runs two separate commands, and only the first get parameter is included in the url.
curl -X PATCH 127.0.0.1:8000/items/notify/?ticket_no=123
foo=bar
Upvotes: 1