Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

66 rindas
1.6 KiB

  1. #!/usr/bin/python
  2. # -*- coding: utf-8; tab-width: 4; indent-tabs-mode: nil; -*-
  3. #
  4. # aggiungiamo la directory corrente al path (se non presente)
  5. #
  6. import sys
  7. wsgilib = '/'.join( __file__.split('/')[:-1] )
  8. if wsgilib not in sys.path:
  9. sys.path.insert(0, wsgilib)
  10. #
  11. # inizializzazione path per templating
  12. #
  13. from decorators import WSGITemplate
  14. WSGITemplate( basedir='views' )
  15. #
  16. # importazione handler
  17. #
  18. from router import WSGIRouter, WSGISmartRouter
  19. #
  20. # index: esempio minimo di applicazione WSGI (pagina iniziale)
  21. #
  22. def index( environ, start_response ):
  23. start_response( '200 OK', [('content-type', 'text/html')] )
  24. return [ 'Index was here' ]
  25. #
  26. # hello: esempio minimo di applicazione WSGI
  27. #
  28. def hello( environ, start_response ):
  29. start_response( '200 OK', [('content-type', 'text/html')] )
  30. return [ 'Simon says: Hello world!' ]
  31. #
  32. # fallback: mostra tutti i parametri disponibili all'applicazione WSGI
  33. #
  34. def fallback( environ, start_response ):
  35. from pprint import pformat
  36. start_response( '200 OK', [('Content-Type', 'text/html')] )
  37. return [
  38. '-- EMBEDDED MODE --' if not environ.get('mod_wsgi.process_group','') else '-- DAEMON MODE --',
  39. '<form method="POST"><input type="submit"/></form>',
  40. pformat( environ, width=132 ).replace('\n','<br>\n'),
  41. ]
  42. #
  43. # definiamo gli handler per le url che vogliamo servire
  44. #
  45. from test_mysql import simple_mysql
  46. handlers = (
  47. ( r'/', index ),
  48. ( r'/hello', hello ),
  49. ( r'/mysql', simple_mysql ),
  50. )
  51. #
  52. # !!! mod_wsgi richiede che la nostra applicazione si chiami 'application'
  53. #
  54. application = WSGISmartRouter( handlers, fallback, cont_dir='controllers' )