Form(Html)+Python
Publicado por Celtha (2 intervenciones) el 11/10/2009 19:53:26
Hola,
Estoy empezando con python, he intento construir una web para atacar a una BBDD MySql
y poder gestionar peliculas.
Lo primero que he hecho es un formulario web para pasar datos a un script python, que se encargara,
de insertar en BBDD
Aquí esta el codigo Html y el Codigo Python,
Html:
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="content-type">
<title></title>
</head>
<body>
Insertar Genero.
<form action="modulos_python/genero.py" method="post">
Genero:<input type="text" name="fgenero" value=""><br>
<input type="submit" value="OK">
</form>
</body>
</html>
Python:
from mod_python import apache
import MySQLdb<html>
db=MySQLdb.connect(host='192.168.1.113',user='root',passwd='XXXXX',db='cine')
cursor=db.cursor()
sql=("INSERT INTO genero VALUES('%s')" %(fgenero))
cursor.execute(sql)
El problema es que al ejecutar el OK de mi formulario pobtengo este error:
Mod_python error: "PythonHandler genero"
Traceback (most recent call last):
File "/usr/lib/python2.4/site-packages/mod_python/apache.py", line 287, in HandlerDispatch
log=debug)
File "/usr/lib/python2.4/site-packages/mod_python/apache.py", line 464, in import_module
module = imp.load_module(mname, f, p, d)
File "/servicios/web/cine/modulos_python/genero.py", line 1
from mod_python import apache
^
SyntaxError: invalid syntax
Aguna sugerencia?
Gracias de antemano.
Estoy empezando con python, he intento construir una web para atacar a una BBDD MySql
y poder gestionar peliculas.
Lo primero que he hecho es un formulario web para pasar datos a un script python, que se encargara,
de insertar en BBDD
Aquí esta el codigo Html y el Codigo Python,
Html:
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="content-type">
<title></title>
</head>
<body>
Insertar Genero.
<form action="modulos_python/genero.py" method="post">
Genero:<input type="text" name="fgenero" value=""><br>
<input type="submit" value="OK">
</form>
</body>
</html>
Python:
from mod_python import apache
import MySQLdb<html>
db=MySQLdb.connect(host='192.168.1.113',user='root',passwd='XXXXX',db='cine')
cursor=db.cursor()
sql=("INSERT INTO genero VALUES('%s')" %(fgenero))
cursor.execute(sql)
El problema es que al ejecutar el OK de mi formulario pobtengo este error:
Mod_python error: "PythonHandler genero"
Traceback (most recent call last):
File "/usr/lib/python2.4/site-packages/mod_python/apache.py", line 287, in HandlerDispatch
log=debug)
File "/usr/lib/python2.4/site-packages/mod_python/apache.py", line 464, in import_module
module = imp.load_module(mname, f, p, d)
File "/servicios/web/cine/modulos_python/genero.py", line 1
from mod_python import apache
^
SyntaxError: invalid syntax
Aguna sugerencia?
Gracias de antemano.
Valora esta pregunta


0