program organization question for web development with python

Hans hansyin at gmail.com
Wed Sep 15 20:14:14 EDT 2010


Hi,

I'm new to this area. Please allow me to ask some (maybe stupid)
questions.

I'm planning to write a web application which used for searching my
mysql database.

1. files organization

I have this in my main.py:
print """<a href="display_tb.py?id=%s&table=%s&cursor=%s">%s</a>""" %
(record[0],table_name,cursor_name,record1)

it kind of works but not comfortable to me.

Do I have to use two files(main.py and display_tb.py)? does that means
each hyper-link needs a single file? Can I put those files together
and then they can share variables,classes, modules, etc?

2. database cursor as parameter?
I created database cursor in my main.py and then I have to use it in
another file(display_tb.py), Can I?  I put cursor as a parameter and
try to send it through hyper-link. but it somehow does not work.
error log listed below:

 /usr/lib/cgi-bin/display_tb.py in ()
   20 sql_str = "SELECT * FROM %s " % search_str_list
   21 print "<p>%s</p>" % sql_str
   22 cursor_ptr.execute(sql_str)
   23 result = cursor_ptr.fetchall()
   24
cursor_ptr = '<MySQLdb.cursors.Cursor object at 0xb786b36c>',
cursor_ptr.execute undefined, sql_str = 'SELECT * FROM env_test where
id=20 '

<type 'exceptions.AttributeError'>: 'str' object has no attribute
'execute'
      args = ("'str' object has no attribute 'execute'",)
      message = "'str' object has no attribute 'execute'"




More information about the Python-list mailing list