[mod_python] importing module

Jim Gallacher jpg at jgassociates.ca
Sat Apr 1 14:27:41 EST 2006


Luis M. Gonzalez wrote:
> I've been trying to solve an import problem, and I came across a strange behaviour when using firefox or opera as web browser.
> This is the script:
> 
>     #myscript.py
>     from utils import table
>     import MySQLdb
>     con = MySQLdb.connect('localhost','root','','vic')
>     cur = con.cursor()
>     cur.execute('select * from clientes')
> 
>     def index(req):
>         req.content_type='text/htm'
>         req.write(table(cur))
> 
> "utils.py" is a module placed in htdocs directory which contains a function for representing tabular data.
> 
> The problem I see is that when trying to access http://localhost/myscript.py,  I get an "Open" dialog in my browser, prompting me to open or save the file on disk.
> It doesn't happend when using Internet Explorer, which works fine.
> 
> What is the problem?

Use req.content_type = 'text/html'. Firefox is picky about the correct 
mime type.

Jim


More information about the Mod_python mailing list