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])
      group = ""
    if request.COOKIES:
      csrf = request.COOKIES['csrftoken']
      return Response({"message": username, "and": group, "but": "no_cookie"})
      return Response({"message": "not available"})
    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 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.