Explorar el Código

modifiche con altri esempi

master
Andrea Papotti hace 13 años
padre
commit
7918f69367
Se han modificado 4 ficheros con 44 adiciones y 3 borrados
  1. +23
    -0
      controllers/demo/auth.py
  2. +6
    -1
      controllers/demo/due.py
  3. +9
    -0
      controllers/pippero.py
  4. +6
    -2
      views/template1.tmpl

+ 23
- 0
controllers/demo/auth.py Ver fichero

@@ -0,0 +1,23 @@
#!/usr/bin/python
# -*- coding: utf-8; tab-width: 4; indent-tabs-mode: nil; -*-

from decorators import WSGITemplate # decoratore ( singleton )
from decorators import WSGISimpleAuth # decoratore ( singleton )


wsgitmpl = WSGITemplate()
wsgiauth = WSGISimpleAuth()

#
# esempio minimo di controller WSGI
#
@wsgiauth.auth()
@wsgitmpl.template()
def application( environ, start_response ):
from pprint import pformat

html = environ['template']( context=dict( v1=1, v2='pippo') )

start_response( '200 OK', [('content-type', 'text/html; charset=utf-8')] )

return [ html ]

+ 6
- 1
controllers/demo/due.py Ver fichero

@@ -11,8 +11,13 @@ wsgitmpl = WSGITemplate()
@wsgitmpl.template( 'template1.tmpl' )
def application( environ, start_response ):
from pprint import pformat
v1=1
v2='pippo'

html = environ['template']( context=dict( v1=1, v2='pippo') )
gino = 'quarantadue'

#html = environ['template']( context=locals() )
html = environ['template']( context=dict( v1=v2, v2=v1, gino='ciao' ) )

start_response( '200 OK', [('content-type', 'text/html; charset=utf-8')] )



+ 9
- 0
controllers/pippero.py Ver fichero

@@ -0,0 +1,9 @@
#!/usr/bin/python
# -*- coding: utf-8; tab-width: 4; indent-tabs-mode: nil; -*-

#
# esempio minimo di controller WSGI
#
def application( environ, start_response ):
start_response( '200 OK', [('content-type', 'text/html')] )
return [ 'Greetings from pippero' ]

+ 6
- 2
views/template1.tmpl Ver fichero

@@ -1,13 +1,17 @@
hello

il valore di v1 è {{= v1 }}
<br>
mentre il valore di v2 è {{= v2 }}
<br>
questo è il risultato di un loop che genera 10 valori casuali:<br>
{{ import random }}
{{ for x in range( 10 ): }}
{{ import random
for x in range( 15 ): }}
<div style='background-color:{{ = random.choice( ('#fcc','yellow','#ccc','cyan',) ) }};'>
{{= random.randint( 10, 100 ) }}
</div>
{{ pass }}



{{= gino }}

Cargando…
Cancelar
Guardar