Diferencia entre revisiones de «Usuario:Lmorillas/desarrollo web servidor/python cgi»

De WikiEducator
Saltar a: navegación, buscar
(Página creada con '{{MiTitulo|Introducción CGI}} {{Objetivo| * http://www.w3.org/CGI/ * http://docs.python.org/2/library/cgi.html |Title= Common Gateway Interface }} {{Actividad| * http://mood…')
 
Línea 3: Línea 3:
  
 
{{Objetivo|
 
{{Objetivo|
* http://www.w3.org/CGI/
+
* '''Especificación:''' http://www.ietf.org/rfc/rfc3875.txt
* http://docs.python.org/2/library/cgi.html
+
* '''Librería python:''' http://docs.python.org/2/library/cgi.html
 +
* '''Un tutorial:''' http://www.tutorialspoint.com/python/python_cgi_programming.htm
 
|Title= Common Gateway Interface
 
|Title= Common Gateway Interface
 
}}
 
}}
Línea 10: Línea 11:
 
{{Actividad|
 
{{Actividad|
 
* http://moodle.cpilosenlaces.com/file.php/266/python/intro_prog_servidor.pdf
 
* http://moodle.cpilosenlaces.com/file.php/266/python/intro_prog_servidor.pdf
 +
}}
 +
 +
{{Tip|
 +
* Para los ejercicios usaremos '''CGIHTTPServer'''
 +
  python -m CGIHTTPServer
 +
* Los programas '''cgi''' estarán en un subdirectorio '''cgi-bin'''
 +
* Esos programas tienen que estar identificados como programas python
 +
  #!/usr/bin/env python
 +
* Tienen que tener permisos de ejecución
 +
  $ chmos +x <programa_cgi.py>
 +
}}
 +
 +
 +
{{Actividad|
 +
===Configuración del servidor===
 +
<source lang="python">
 +
#!/usr/bin/env python
 +
 +
import BaseHTTPServer
 +
import CGIHTTPServer
 +
import cgitb; cgitb.enable()  ## Para mostrar errores CGI
 +
 +
server = BaseHTTPServer.HTTPServer
 +
handler = CGIHTTPServer.CGIHTTPRequestHandler
 +
server_address = ("", 8000)
 +
handler.cgi_directories = [""]  ## En qué directorios puede haber programas CGI
 +
 +
httpd = server(server_address, handler)
 +
httpd.serve_forever()
 +
</source>
 
}}
 
}}

Revisión de 17:28 16 oct 2013







Icon present.gif
Tip:
  • Para los ejercicios usaremos CGIHTTPServer
 python -m CGIHTTPServer
  • Los programas cgi estarán en un subdirectorio cgi-bin
  • Esos programas tienen que estar identificados como programas python
 #!/usr/bin/env python
  • Tienen que tener permisos de ejecución
 $ chmos +x <programa_cgi.py>




Icon activity.jpg

Actividad

Configuración del servidor

#!/usr/bin/env python
 
import BaseHTTPServer
import CGIHTTPServer
import cgitb; cgitb.enable()  ## Para mostrar errores CGI
 
server = BaseHTTPServer.HTTPServer
handler = CGIHTTPServer.CGIHTTPRequestHandler
server_address = ("", 8000)
handler.cgi_directories = [""]  ## En qué directorios puede haber programas CGI
 
httpd = server(server_address, handler)
httpd.serve_forever()