Z
Z
zlodiak2020-01-03 19:49:09
Django
zlodiak, 2020-01-03 19:49:09

How to get a GET parameter?

I make a request in which I pass a GET parameter. On the backend side, in the corresponding view, Jangi is trying to print this parameter to the console using the print statement. But in the console I get the following error message:

print('=-=-=', request.GET["user_id"])


[03/Jan/2021 16:41:24] "OPTIONS /victims?user_id=2 HTTP/1.1" 500 65915
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 60734)
Traceback (most recent call last):
  File "/usr/lib/python3.6/socketserver.py", line 654, in process_request_thread
    self.finish_request(request, client_address)
  File "/usr/lib/python3.6/socketserver.py", line 364, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/lib/python3.6/socketserver.py", line 724, in __init__
    self.handle()
  File "/home/md/.MINT18/code/python/vkiller-backend/venv/lib/python3.6/site-packages/django/core/servers/basehttp.py", line 174, in handle
    self.handle_one_request()
  File "/home/md/.MINT18/code/python/vkiller-backend/venv/lib/python3.6/site-packages/django/core/servers/basehttp.py", line 182, in handle_one_request
    self.raw_requestline = self.rfile.readline(65537)
  File "/usr/lib/python3.6/socket.py", line 586, in readinto
    return self._sock.recv_into(b)
ConnectionResetError: [Errno 104] Connection reset by peer


At the same time, if I write the print statement like this: Then there is no error in the console, but it is displayed:

print('=-=-=', request.GET)

System check identified no issues (0 silenced).
January 03, 2021 - 16:42:55
Django version 3.1.4, using settings 'vkiller.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
=-=-= <QueryDict: {'user_id': ['2']}>
=-=-= <QueryDict: {'user_id': ['2']}>
Internal Server Error: /victims
Traceback (most recent call last):
  File "/home/md/.MINT18/code/python/vkiller-backend/venv/lib/python3.6/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/home/md/.MINT18/code/python/vkiller-backend/venv/lib/python3.6/site-packages/django/core/handlers/base.py", line 179, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/md/.MINT18/code/python/vkiller-backend/victims/views.py", line 25, in victims
    return JsonResponse({'isLogged': isLogged})
NameError: name 'isLogged' is not defined
[03/Jan/2021 16:42:58] "OPTIONS /victims?user_id=2 HTTP/1.1" 500 65915


Please help me to display the value of the GET parameter in the first way

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2021-01-10
@SergeiKl

print('=-=-=', request.GET.get("user_id"))
so try

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question