| @@ -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 ] | |||||
| @@ -11,8 +11,13 @@ wsgitmpl = WSGITemplate() | |||||
| @wsgitmpl.template( 'template1.tmpl' ) | @wsgitmpl.template( 'template1.tmpl' ) | ||||
| def application( environ, start_response ): | def application( environ, start_response ): | ||||
| from pprint import pformat | 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')] ) | start_response( '200 OK', [('content-type', 'text/html; charset=utf-8')] ) | ||||
| @@ -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' ] | |||||
| @@ -1,13 +1,17 @@ | |||||
| hello | |||||
| il valore di v1 è {{= v1 }} | il valore di v1 è {{= v1 }} | ||||
| <br> | <br> | ||||
| mentre il valore di v2 è {{= v2 }} | mentre il valore di v2 è {{= v2 }} | ||||
| <br> | <br> | ||||
| questo è il risultato di un loop che genera 10 valori casuali:<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',) ) }};'> | <div style='background-color:{{ = random.choice( ('#fcc','yellow','#ccc','cyan',) ) }};'> | ||||
| {{= random.randint( 10, 100 ) }} | {{= random.randint( 10, 100 ) }} | ||||
| </div> | </div> | ||||
| {{ pass }} | {{ pass }} | ||||
| {{= gino }} | |||||