Python - ¿Cómo importar archivos .py en una página psp?

 
Vista:

¿Cómo importar archivos .py en una página psp?

Publicado por Sioli (3 intervenciones) el 04/02/2009 19:40:10
Buenas tardes.

Actualmente me encuentro estudiando la plataforma Web para Python, ya configure el servidor Web apache en Debian. He realizado varios ejercicios sencillos para verificar que el servidor funciona correctamente. Pero ahora se me presenta otro inconveniente, estoy tratando de usar algunas funciones matematicas que tengo en un archivo llamado funciones.py, por ejemplo:

# este archivo se llama funciones.py y contiene el siguiente código:

import math
from numpy import array

def PbEstandar(Rsb,T,gegas,API):
f1= float ((10 **((0.00091*T)-(0.0125*API))))
F= float(((Rsb/gegas)**0.83)*f1)
Pb=float(18.2*(F-1.4))
return Pb

Es una funcion que realiza una operacion matemática y que recibre Rsb, T, gegas y API como parámetros y después de realizar el cálculo devuelve el resultado en la variable Pb.

Ahora bien, este es el ejemplo de la página prueba.psp que es donde se llama a la funcion PbEstandar del archivo funciones.py, de la siguiente manera:

# este es el archivo prueba.psp y contiene el siguiente código

<% import time %>
<% import math %>
<%@ import funciones.py %>

<html>
<meta content_type = 'text/html'>
<body>
<% tiempo = time.strftime('%Y') %>
<table width="200" border="1">
<tr>
<td><%= funciones.PbEstandar(650.00,200.00,0.75,36.00)%></td>
</tr>
<tr>
<td><%= tiempo %></td>
</tr>
<tr>
<td><%--= funciones.PbEstandar(650.00,200.00,0.75,36.00) --%></td>
</tr>
</table>

<h1>Current time is: <%= time.ctime() %></h1>
<br>
<h1>The square root of 25 is: <%= math.sqrt(25) %></h1>
</body>
</html>

Los archivos funciones.py y prueba.psp se encuentra en el mismo directorio, /www/prueba_general/

Al ejecutarse en el navegador la página prueba.psp da el siguiente error:

Mod_python error: "PythonHandler mod_python.psp"

Traceback (most recent call last):

File "/usr/lib/python2.4/site-packages/mod_python/apache.py", line 299, in HandlerDispatch
result = object(req)

File "/usr/lib/python2.4/site-packages/mod_python/psp.py", line 302, in handler
p.run()

File "/usr/lib/python2.4/site-packages/mod_python/psp.py", line 213, in run
exec code in global_scope

File "/var/www/prueba_general/prueba_psp.psp", line 1, in ?

NameError: name 'funciones' is not defined

Si alguien me puede ayudar a descifrar este error se lo agradece... gracias!
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:¿Cómo importar archivos .py en una página psp?

Publicado por Sioli (3 intervenciones) el 18/02/2009 15:46:07
Bueno aquí les dejo la manera en que nos funcionó, sólo agregamos en el archivo de configuración en el apache2 las rutas donde se almacenan los archivos a importar, espero les sea útil a ustedes tambien :)

/etc/apache2/sites-available/default

<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all

AddHandler mod_python .py .psp
PythonPath "['/var/www/prueba_general','/var/www/sibma','/var/www/sibma/py','/var/www/sibma/psp','/var/www/sibma/configuracion'] + sys.path"
PythonHandler mod_python.publisher | .py
PythonHandler mod_python.psp | .psp
PythonDebug On

# This directive allows us to have apache2's default start page
# in /apache2-default/, but still have / go to the right place
RedirectMatch ^/$ /apache2-default/
</Directory>
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar