Attachment 'views.py'

Download

   1 from django.shortcuts import render_to_response
   2 
   3 def addnumber(request,what):
   4 
   5     if not what or not 'numbers' in request.session:
   6         request.session['numbers']=[]
   7     else:
   8         try:
   9             what_int=int(what)
  10             request.session['numbers']+=[what_int]
  11         except:
  12             pass
  13     numbers=request.session['numbers']
  14     candidates=range(1,10)
  15     return render_to_response('add.html',
  16         {'numbers':numbers,'candidates':candidates} )
  17 
  18 def addnull(request):
  19     
  20     return addnumber(request,None)
  21 
  22 def sum(request):
  23 
  24     if not 'numbers' in request.session:
  25         request.session['numbers']=[]
  26     sum=0
  27     for num in request.session['numbers']:
  28         sum+=num
  29     request.session['numbers']=[]
  30     return render_to_response('sum.html',{'sum':sum} )
  31     
  32     
  33 
  34     

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2009-03-24 21:03:16, 7.9 KB) [[attachment:sessions.tar.gz]]
  • [get | view] (2009-03-24 21:02:31, 0.8 KB) [[attachment:views.py]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.