from django.http import HttpResponse
from django.utils.html import escape
def hello_html(request):
"This view is a basic 'hello world' example in HTML."
return HttpResponse('
Hello, world.
')
def hello_text(request):
"This view is a basic 'hello world' example in plain text."
return HttpResponse('Hello, world.', mimetype='text/plain')
def hello_write(request):
"This view demonstrates how an HttpResponse object has a write() method."
r = HttpResponse()
r.write("Here's a paragraph.
")
r.write("Here's another paragraph.
")
return r
def metadata(request):
"This view demonstrates how to retrieve request metadata, such as HTTP headers."
r = HttpResponse('All about you
')
r.write("Here's all known metadata about your request, according to request.META
:
")
r.write('')
meta_items = request.META.items()
meta_items.sort()
for k, v in meta_items:
r.write('%s | %r |
' % (k, v))
r.write('
')
return r
def get_data(request):
"This view demonstrates how to retrieve GET data."
r = HttpResponse()
if request.GET:
r.write('GET data found! Here it is:
')
r.write('' % ''.join(['%s: %r' % (escape(k), escape(v)) for k, v in request.GET.items()]))
r.write('')
return r
def post_data(request):
"This view demonstrates how to retrieve POST data."
r = HttpResponse()
if request.POST:
r.write('POST data found! Here it is:
')
r.write('' % ''.join(['%s: %r' % (escape(k), escape(v)) for k, v in request.POST.items()]))
r.write('')
return r