14

I want to print the entire request object that comes to the server. I need to see all of the parameters that the request carries from the client since I don't have the clients's code (it's an Android client). I'm in the view.py file, and I'm using the function

def index(request):

    return HttpResponse("test params")

to print the request object

Please suggest code. It would be even better if I can print the request in the browser and not in the console.

4
  • 1
    print request is for console. Commented Feb 16, 2013 at 15:01
  • return HttpResponse(request) ? Commented Feb 16, 2013 at 15:09
  • return HttpResponse(request) is not working I get a empty webpage Commented Feb 16, 2013 at 15:38
  • 1
    Try render(request, 'mypage.html', {'request': request}). Commented Dec 1, 2017 at 17:04

3 Answers 3

11
import sys

def req(request)
   print(request.__dict__, file=sys.stderr)
Sign up to request clarification or add additional context in comments.

1 Comment

Faster/easier than the accepted answer
6

You can use Django Debug Toolbar which allows you to view a lot of debugging information including request and session.

From its documentation:

Currently, the following panels have been written and are working:

  • Django version
  • Request timer
  • A list of settings in settings.py
  • Common HTTP headers
  • GET/POST/cookie/session variable display
  • Templates and context used, and their template paths
  • SQL queries including time to execute and links to EXPLAIN each query
  • List of signals, their args and receivers
  • Logging output via Python's built-in logging, or via the logbook module

Comments

6
from django.utils.html import escape
def index(request):
    return HttpResponse(escape(repr(request)))

1 Comment

This just returns <WSGIRequest: GET '/path/to/endpoint/'> now

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.