[Tutor] Help with CGI output

Lindsay Davies Lindsay.Davies@moonshine.co.uk
Thu, 22 Feb 2001 14:31:19 +0000


These lines won't help things...

>     print 'http://10.104.98.70/medintouch/images'
>   # print os.getcwd() + '\\' + x
>     print '/' + x
>     print '"></td>'


They will output something like...

http://10.104.98.70/medintouch/images
/some.gif
"></td>

...which isn't going to make a web server terribly happy to oblige 
you because of the carriage returns output by the print statements 
which are screwing up the URL. You can wrap your HTML in triple 
quotes and use string formatting to make it easier to deal with. eg

print """<img src="http://10.104.98.70/medintouch/images/%s">""" % x




On 22/2/01, Sharriff Aina wrote about '[Tutor] Help with CGI output':
>Hi guys!
>
>Im trying to generate thumbnails of images per CGI, somehow, my script is
>not behaving as it should, could someone please have a look at my code?
>Please excuse my sloppy coding, this is a test scipt that Ill clean up
>when I get everything working.
>
>Thanks a million!
>
>Sharriff
>
>
>The code
>----------------------
>#!C:/Python/python.exe -u
>
>print "Content-Type: text/html\n\n"
>
>
>import cgi
>import os
>#
>#
>
>os.chdir("c:\\Xitami\medintouch\images")
>test2 = os.getcwd()
>print "<html><title>test</title>"
>print '<body>'
>print "<br></br>"
>print "saving HTML file to disk..."
>print "<br></br>"
>print test2
>print "<br></br>"
>templist = os.listdir("c:\\Xitami\medintouch\images")
>print '<table border="1">'
>for x in templist:
>     print '<tr>'
>     print '<td>'   
>     print x
>     print '</td>'
>     print '<td><img src="'
>     print '<img src="'
>     print 'http://10.104.98.70/medintouch/images'
>   # print os.getcwd() + '\\' + x
>     print '/' + x
>     print '"></td>'
>     print '<td><input type="checkbox"></input></td>'
>     print '<tr>'
>print '</table>'
>print '</body>'
>print '</html>'
>
>
>I just cant get the images to show up on my pages :-(
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor