diff options
| author | Adrian Holovaty <adrian@holovaty.com> | 2006-05-02 01:31:56 +0000 |
|---|---|---|
| committer | Adrian Holovaty <adrian@holovaty.com> | 2006-05-02 01:31:56 +0000 |
| commit | f69cf70ed813a8cd7e1f963a14ae39103e8d5265 (patch) | |
| tree | d3b32e84cd66573b3833ddf662af020f8ef2f7a8 /examples/hello | |
| parent | d5dbeaa9be359a4c794885c2e9f1b5a7e5e51fb8 (diff) | |
MERGED MAGIC-REMOVAL BRANCH TO TRUNK. This change is highly backwards-incompatible. Please read http://code.djangoproject.com/wiki/RemovingTheMagic for upgrade instructions.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@2809 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'examples/hello')
| -rw-r--r-- | examples/hello/__init__.py | 0 | ||||
| -rw-r--r-- | examples/hello/urls.py | 10 | ||||
| -rw-r--r-- | examples/hello/views.py | 55 |
3 files changed, 65 insertions, 0 deletions
diff --git a/examples/hello/__init__.py b/examples/hello/__init__.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/examples/hello/__init__.py diff --git a/examples/hello/urls.py b/examples/hello/urls.py new file mode 100644 index 0000000000..e57c2b8e8c --- /dev/null +++ b/examples/hello/urls.py @@ -0,0 +1,10 @@ +from django.conf.urls.defaults import * + +urlpatterns = patterns('examples.hello.views', + (r'^html/$', 'hello_html'), + (r'^text/$', 'hello_text'), + (r'^write/$', 'hello_write'), + (r'^metadata/$', 'metadata'), + (r'^getdata/$', 'get_data'), + (r'^postdata/$', 'post_data'), +) diff --git a/examples/hello/views.py b/examples/hello/views.py new file mode 100644 index 0000000000..07f955a38d --- /dev/null +++ b/examples/hello/views.py @@ -0,0 +1,55 @@ +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('<h1>Hello, world.</h1>') + +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("<p>Here's a paragraph.</p>") + r.write("<p>Here's another paragraph.</p>") + return r + +def metadata(request): + "This view demonstrates how to retrieve request metadata, such as HTTP headers." + r = HttpResponse('<h1>All about you</h1>') + r.write("<p>Here's all known metadata about your request, according to <code>request.META</code>:</p>") + r.write('<table>') + meta_items = request.META.items() + meta_items.sort() + for k, v in meta_items: + r.write('<tr><th>%s</th><td>%r</td></tr>' % (k, v)) + r.write('</table>') + return r + +def get_data(request): + "This view demonstrates how to retrieve GET data." + r = HttpResponse() + if request.GET: + r.write('<p>GET data found! Here it is:</p>') + r.write('<ul>%s</ul>' % ''.join(['<li><strong>%s:</strong> %r</li>' % (escape(k), escape(v)) for k, v in request.GET.items()])) + r.write('<form action="" method="get">') + r.write('<p>First name: <input type="text" name="first_name"></p>') + r.write('<p>Last name: <input type="text" name="last_name"></p>') + r.write('<p><input type="submit" value="Submit"></p>') + r.write('</form>') + return r + +def post_data(request): + "This view demonstrates how to retrieve POST data." + r = HttpResponse() + if request.POST: + r.write('<p>POST data found! Here it is:</p>') + r.write('<ul>%s</ul>' % ''.join(['<li><strong>%s:</strong> %r</li>' % (escape(k), escape(v)) for k, v in request.POST.items()])) + r.write('<form action="" method="post">') + r.write('<p>First name: <input type="text" name="first_name"></p>') + r.write('<p>Last name: <input type="text" name="last_name"></p>') + r.write('<p><input type="submit" value="Submit"></p>') + r.write('</form>') + return r |
