Skip to content

Commit 0dbb05e

Browse files
author
Manny Blum
committed
Creating the time view example from chapter 3
1 parent 3f6d017 commit 0dbb05e

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

urls.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from django.conf.urls.defaults import *
2-
from mysite.views import hello
2+
from mysite.views import hello, current_datetime
33

44
# Uncomment the next two lines to enable the admin:
55
# from django.contrib import admin
@@ -10,6 +10,7 @@
1010
# url(r'^$', 'mysite.views.home', name='home'),
1111
# url(r'^mysite/', include('mysite.foo.urls')),
1212
url('^hello/$', hello),
13+
url('^time/$', current_datetime),
1314
# Uncomment the admin/doc line below to enable admin documentation:
1415
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
1516

views.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
from django.http import HttpResponse
2+
import datetime
23

34
def hello(request):
45
return HttpResponse("Hello World")
6+
7+
def current_datetime(request):
8+
now = datetime.datetime.now()
9+
html = "<html><body>It is now %s.</body></html>" % now
10+
return HttpResponse(html)

0 commit comments

Comments
 (0)