Guest User

Untitled

a guest
Oct 5th, 2018
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.10 KB | None | 0 0
  1. # -*- coding: utf-8 *-*
  2. from sys import path
  3. from string import Template
  4.  
  5.  
  6. path.append('/home/eugenia/Cursos/pyweb/application')
  7.  
  8.  
  9. def application(environ, start_response):
  10.  
  11.     peticion = environ['REQUEST_URI']
  12.  
  13.     if peticion == '/contacto':
  14.         output = mostrar_form_contacto()
  15.     elif peticion == "/contactar":
  16.         output = contactar(environ)
  17.     elif peticion == "/holamundo":
  18.         output = mostrar_html()
  19.  
  20.     start_response('200 OK', [('Content-Type', 'text/html; charset=utf-8')])
  21.  
  22.     return output
  23.  
  24.  
  25. def contactar(environ):
  26.     datos_del_form = environ['wsgi.input'].read()
  27. #    datos = datos_del_form.split('&')
  28. #    datos = ['user=pepegrillo', 'pass=123456'].split('=')
  29. #    ['user', 'pepegrillo']
  30.  
  31. def mostrar_form_contacto():
  32.     return "Estoy mostrando un form de contacto"
  33.  
  34.  
  35. def mostrar_html():
  36.     ruta = "/home/eugenia/Cursos/pyweb/application/archivo.html"
  37.  
  38.     with open(ruta, 'r') as archivo:
  39.         contenido = archivo.read()
  40.  
  41.     diccionario = dict(precio='28.80')
  42.  
  43.     html = Template(contenido).safe_substitute(diccionario)
  44.  
  45.     return html
Add Comment
Please, Sign In to add comment