Django print request.COOKIES glitch

@api_view(['GET', 'POST'])
def token(request):
  if request.user.is_authenticated:
    username = request.user.username
    query = User.objects.get(username=username)
    group = query.groups.all()
    if group:
      group = str(group[0])
    else:
      group = ""
    if request.COOKIES:
      print(request.COOKIES)
      csrf = request.COOKIES['csrftoken']
      print(csrf)
      print('suyash')
      return Response({"message": username, "and": group, "but": "no_cookie"})
    else:
      return Response({"message": "not available"})
  else:
    return Response({"message": "Please sign in to see content."})

The above code is written with intention to print cookies in the console. It is in views.py. The above @api_view decorator is from rest_framework. The code doesn’t ouput any dictionary of cookies in terminal until print(‘suyash’) is in the next line. Also any edit to the code in the lines above then print(‘suyash’) and saving it and making get request in browser doesn’t print any cookies dictonary. I can’t understand.

Welcome @suyashpriyadarshi7 !

Python output from the print function is buffered by default. If you want the output generated immediately, you either need to run Python unbuffered, set the PYTHONUNBUFFERED environment variable, add the flush argument to the print calls, or use the flush function on the output stream.

Thanks Ken for the solution.