1 from django
.http
import HttpResponse
2 from django
.utils
.html
import escape
4 def hello_html(request
):
5 "This view is a basic 'hello world' example in HTML."
6 return HttpResponse('<h1>Hello, world.</h1>')
8 def hello_text(request
):
9 "This view is a basic 'hello world' example in plain text."
10 return HttpResponse('Hello, world.', mimetype
='text/plain')
12 def hello_write(request
):
13 "This view demonstrates how an HttpResponse object has a write() method."
15 r
.write("<p>Here's a paragraph.</p>")
16 r
.write("<p>Here's another paragraph.</p>")
19 def metadata(request
):
20 "This view demonstrates how to retrieve request metadata, such as HTTP headers."
21 r
= HttpResponse('<h1>All about you</h1>')
22 r
.write("<p>Here's all known metadata about your request, according to <code>request.META</code>:</p>")
24 meta_items
= request
.META
.items()
26 for k
, v
in meta_items
:
27 r
.write('<tr><th>%s</th><td>%r</td></tr>' % (k
, v
))
31 def get_data(request
):
32 "This view demonstrates how to retrieve GET data."
35 r
.write('<p>GET data found! Here it is:</p>')
36 r
.write('<ul>%s</ul>' % ''.join(['<li><strong>%s:</strong> %r</li>' % (escape(k
), escape(v
)) for k
, v
in request
.GET
.items()]))
37 r
.write('<form action="" method="get">')
38 r
.write('<p>First name: <input type="text" name="first_name"></p>')
39 r
.write('<p>Last name: <input type="text" name="last_name"></p>')
40 r
.write('<p><input type="submit" value="Submit"></p>')
44 def post_data(request
):
45 "This view demonstrates how to retrieve POST data."
48 r
.write('<p>POST data found! Here it is:</p>')
49 r
.write('<ul>%s</ul>' % ''.join(['<li><strong>%s:</strong> %r</li>' % (escape(k
), escape(v
)) for k
, v
in request
.POST
.items()]))
50 r
.write('<form action="" method="post">')
51 r
.write('<p>First name: <input type="text" name="first_name"></p>')
52 r
.write('<p>Last name: <input type="text" name="last_name"></p>')
53 r
.write('<p><input type="submit" value="Submit"></p>')