Ticket #2492: views.py

File views.py, 1.5 KB (added by anonymous, 17 years ago)
Line 
1from django.template import Template, Context
2from django.http import HttpResponse
3
4import datetime
5
6from django.template import Context, loader
7from django.http import HttpResponse
8
9#def current_datetime(request) :
10 # now = datetime.datetime.now()
11 # html = "<html><body> It is now %s </body></html>" % now
12 # return HttpResponse(html)
13
14def hours_offset(request, plus_or_minus,offset) :
15 offset = int(offset)
16 if plus_or_minus == 'plus':
17 dt = datetime.datetime.now() + datetime.timedelta(hours=offset)
18 html = "<html><body> In %s hours it will be %s.</body></html> " %(offset,dt)
19 else:
20 dt = datetime.datetime.now() - datetime.timedelta(hours=offset)
21 html = "<html><body> %s hours ago it was %s. </body></html>" %(offset,dt)
22 return HttpResponse(html)
23
24def hello(request) :
25 return HttpResponse("Hallo Aditi")
26
27def current_datetime(request):
28 now = datetime.datetime.now()
29 t = Template("<html><body>It is now {{ current_date }}.</body></html>")
30 html = t.render(Context({'current_date' : now}))
31 return HttpResponse(html)
32
33def temp(request):
34 t = loader.get_template('hello.html');
35 c = Context({
36 'dir':'hello' ,
37 'name':'Aditi'
38 })
39 return HttpResponse(t.render(c))
40
41def order(request):
42 t = loader.get_template('order.html');
43 c = Context({
44 'person_name': 'John'
45... #'product': 'SuperLawnMower',
46... #'company': 'Outdoor Equipment',
47... #'ship_date': datetime.date(2009, 4, 2),
48... #'ordered_warranty': True
49 })
50 return HttpResponse(t.render(c))
Back to Top