I want transmit a GET parameters 'pk' to django rest-framework.
Browser
but in my view.py I was setting my GET method to receive ‘pk’ parameters.
views.py
It's urls.py code:
and There is another one question,if I models object use 'objects' method in the pycharm,were throw an exception,such as:
but my friend was not happen this exception. He use pycharm 2017.4(macOS)
cateloydata = category.objects.all()
my pycharm version:pycharm 2017.2 python version 3.6 django version 1.11.7
Thank everyone.
and I'm sorry, I need at least 10 reputation to post images. So my question composing is very bad.
感谢!
When you are adding params to your url, you have to add an extra param to your method definition, like this:
# urls.py
url(r'^questions/(?P<pk>[\w:|-]+)/$', TheView.as_view(), name='view')
In the url above, you are passing a url param (pk) so you have to receive it in the method:
# views.py
class TheView(APIView):
def get(self, request, pk):
...
But in your case, you want to pass data by query params.
# urls.py
url(r'^questions/$', TheView.as_view(), name='view')
so you don't have to receive it in the method declaration, use:
def get(self, request):
pk = request.GET.get('pk')
instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With