diff --git a/controllers/demo/auth.py b/controllers/demo/auth.py new file mode 100644 index 0000000..354440e --- /dev/null +++ b/controllers/demo/auth.py @@ -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 ] \ No newline at end of file diff --git a/controllers/demo/due.py b/controllers/demo/due.py index 993fc44..5b7d652 100644 --- a/controllers/demo/due.py +++ b/controllers/demo/due.py @@ -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')] ) diff --git a/controllers/pippero.py b/controllers/pippero.py new file mode 100644 index 0000000..3feca8c --- /dev/null +++ b/controllers/pippero.py @@ -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' ] \ No newline at end of file diff --git a/views/template1.tmpl b/views/template1.tmpl index ea35cdc..b83bc49 100644 --- a/views/template1.tmpl +++ b/views/template1.tmpl @@ -1,13 +1,17 @@ +hello il valore di v1 è {{= v1 }}
mentre il valore di v2 è {{= v2 }}
questo è il risultato di un loop che genera 10 valori casuali:
-{{ import random }} -{{ for x in range( 10 ): }} +{{ import random + for x in range( 15 ): }}
{{= random.randint( 10, 100 ) }}
{{ pass }} + + +{{= gino }}