Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print HTTP request in Python Django

Tags:

python

django

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.

like image 559
user1796624 Avatar asked Feb 16 '13 14:02

user1796624


People also ask

Can you print in Django?

Yes, you can print directly to a printer from Django (or any web app) using this method.

How a request is processed in Django?

Django uses request and response objects to pass state through the system. When a page is requested, Django creates an HttpRequest object that contains metadata about the request. Then Django loads the appropriate view, passing the HttpRequest as the first argument to the view function.

What is HTTP response in Django?

HttpResponse Methods – DjangoIt is used to instantiate an HttpResponse object with the given page content and content type. HttpResponse.__setitem__(header, value) It is used to set the given header name to the given value.

What is QueryDict Django?

In an HttpRequest object, the GET and POST attributes are instances of django. http. QueryDict , a dictionary-like class customized to deal with multiple values for the same key. This is necessary because some HTML form elements, notably <select multiple> , pass multiple values for the same key.


1 Answers

from django.utils.html import escape
def index(request):
    return HttpResponse(escape(repr(request)))
like image 189
mderk Avatar answered Oct 02 '22 13:10

mderk