FAQ
Hi;
Gabriel provided a lovely script for showing images which I am modifying for
my needs. I have the following line:

print '<img src="getpic.py?id=%d&x=%d"><br /><br /></td>\n' % (d, y)
where the correct values are entered for the variables, and those values
increment (already tested). Here is the slightly modified script it calls:


#!/usr/local/bin/python
import cgitb; cgitb.enable()
import MySQLdb
import cgi
form = cgi.FieldStorage()
picid = int(form["id"].value)
x = int(form["x"].value)
pic = str(x)
print 'Content-Type: text/html'
db = MySQLdb.connect(host=host, user=user, passwd=passwd, db=db)
cursor= db.cursor()
sql = "select " + pic + " from products where id='" + str(picid) + "';"
cursor.execute(sql)
content = cursor.fetchall()[0][0].tostring()
cursor.close()
print 'Content-Type: image/jpeg\r\nContent-Length: %s\n' % len(content)
print content

I need to make it so that it will show all my images, not just the last one.
Suggestions, please.
TIA,
Victor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-list/attachments/20080417/2dc7298e/attachment.htm

Search Discussions

  • Steve Holden at Apr 17, 2008 at 6:07 pm

    Victor Subervi wrote:
    Hi;
    Gabriel provided a lovely script for showing images which I am modifying
    for my needs. I have the following line:

    print '<img src="getpic.py?id=%d&x=%d"><br /><br /></td>\n' % (d, y)
    where the correct values are entered for the variables, and those values
    increment (already tested). Here is the slightly modified script it calls:


    #!/usr/local/bin/python
    import cgitb; cgitb.enable()
    import MySQLdb
    import cgi
    form = cgi.FieldStorage()
    picid = int(form["id"].value)
    x = int(form["x"].value)
    pic = str(x)
    print 'Content-Type: text/html'
    db = MySQLdb.connect(host=host, user=user, passwd=passwd, db=db)
    cursor= db.cursor()
    sql = "select " + pic + " from products where id='" + str(picid) + "';"
    cursor.execute(sql)
    content = cursor.fetchall()[0][0].tostring()
    cursor.close()
    print 'Content-Type: image/jpeg\r\nContent-Length: %s\n' % len(content)
    print content

    I need to make it so that it will show all my images, not just the last
    one. Suggestions, please.
    TIA,
    Victor
    In your "page generator" page, replace

    print '<img src="getpic.py?id=%d&x=%d"><br /><br /></td>\n' % (d, y)

    by

    for d, y in (results of some DB query to get d and y for each image):
    print '<img src="getpic.py?id=%d&x=%d"><br /><br /></td>\n' % (d, y)

    regards
    Steve
    --
    Steve Holden +1 571 484 6266 +1 800 494 3119
    Holden Web LLC http://www.holdenweb.com/
  • Victor Subervi at Apr 17, 2008 at 6:51 pm

    On Thu, Apr 17, 2008 at 1:07 PM, Steve Holden wrote:

    Victor Subervi wrote:
    Hi;
    Gabriel provided a lovely script for showing images which I am modifying
    for my needs. I have the following line:
    print '<img src="getpic.py?id=%d&x=%d"><br /><br /></td>\n' % (d, y)
    where the correct values are entered for the variables, and those values
    increment (already tested). Here is the slightly modified script it calls:
    #!/usr/local/bin/python
    import cgitb; cgitb.enable()
    import MySQLdb
    import cgi
    form = cgi.FieldStorage()
    picid = int(form["id"].value)
    x = int(form["x"].value)
    pic = str(x)
    print 'Content-Type: text/html'
    db = MySQLdb.connect(host=host, user=user, passwd=passwd, db=db)
    cursor= db.cursor()
    sql = "select " + pic + " from products where id='" + str(picid) + "';"
    cursor.execute(sql)
    content = cursor.fetchall()[0][0].tostring()
    cursor.close()
    print 'Content-Type: image/jpeg\r\nContent-Length: %s\n' % len(content)
    print content
    I need to make it so that it will show all my images, not just the last
    one. Suggestions, please.
    TIA,
    Victor

    In your "page generator" page, replace
    print '<img src="getpic.py?id=%d&x=%d"><br /><br /></td>\n' % (d, y)

    by

    for d, y in (results of some DB query to get d and y for each image):
    print '<img src="getpic.py?id=%d&x=%d"><br /><br /></td>\n' % (d, y)
    Well, I just tried this:

    #! /usr/bin/python
    print """Content-type: text/html
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title></title>
    </head>
    <body>
    <input type='hidden' name='db' value='benobeno_bre' />
    """
    y = 1
    for d in 2, 12:
    while y < 12:
    print '<img src="getpic.py?id=%d&x=%d"><br /><br /></td>\n' % (d, y)
    y += 1
    print"""
    </body>
    </html>"""
    and it printed the same image over and over again :(
    Now, I could write a generator function that writes and then executes a new
    program for each image "getpic" + i + "py?... but that is ugly.
    Victor
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: http://mail.python.org/pipermail/python-list/attachments/20080417/727da864/attachment.htm
  • Gabriel Genellina at Apr 21, 2008 at 5:45 am

    En Thu, 17 Apr 2008 15:51:43 -0300, Victor Subervi <victorsubervi at gmail.com> escribi?:
    On Thu, Apr 17, 2008 at 1:07 PM, Steve Holden wrote:
    Victor Subervi wrote:
    Gabriel provided a lovely script for showing images which I am modifying
    for my needs. I have the following line:
    print '<img src="getpic.py?id=%d&x=%d"><br /><br /></td>\n' % (d, y)
    where the correct values are entered for the variables, and those values
    increment (already tested). Here is the slightly modified script it calls:
    #!/usr/local/bin/python
    import cgitb; cgitb.enable()
    import MySQLdb
    import cgi
    form = cgi.FieldStorage()
    picid = int(form["id"].value)
    x = int(form["x"].value)
    pic = str(x)
    print 'Content-Type: text/html'
    db = MySQLdb.connect(host=host, user=user, passwd=passwd, db=db)
    cursor= db.cursor()
    sql = "select " + pic + " from products where id='" + str(picid) + "';"
    cursor.execute(sql)
    content = cursor.fetchall()[0][0].tostring()
    cursor.close()
    print 'Content-Type: image/jpeg\r\nContent-Length: %s\n' % len(content)
    print content
    I need to make it so that it will show all my images, not just the last
    one. Suggestions, please.
    That 'Content-Type: text/html' is wrong, you're returning an image here.
    Are you sure that *different* pictures are stored in the database? Perhaps there was an error and all columns have the same picture.
    Also make sure you're not seeing a cached image in your browser.

    In your "page generator" page, replace
    print '<img src="getpic.py?id=%d&x=%d"><br /><br /></td>\n' % (d, y)

    by

    for d, y in (results of some DB query to get d and y for each image):
    print '<img src="getpic.py?id=%d&x=%d"><br /><br /></td>\n' % (d, y)
    Well, I just tried this:

    #! /usr/bin/python
    print """Content-type: text/html
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title></title>
    </head>
    <body>
    <input type='hidden' name='db' value='benobeno_bre' />
    """
    y = 1
    for d in 2, 12:
    while y < 12:
    print '<img src="getpic.py?id=%d&x=%d"><br /><br /></td>\n' % (d, y)
    y += 1
    print"""
    </body>
    </html>"""
    and it printed the same image over and over again :(
    An empty line is missing after Content-Type and before the actual content.
    Look at the source and be sure the src= attribute is generated correctly.

    --
    Gabriel Genellina

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedApr 17, '08 at 4:22p
activeApr 21, '08 at 5:45a
posts4
users3
websitepython.org

People

Translate

site design / logo © 2022 Grokbase