Ran both the method #!/usr/bin/env python
import cgi import psycopg2 import sys print """Content-type:text/html\r\n\r\n""" print """<html> <head> <title>Hello Word - First CGI Program</title> </head> <body> <h2>Hello Word! This is my first CGI program</h2> <p>{version}</p> First name: <input type="text" name="fname"><br> </body> </html>""".format(version=sys.version) and its output (below) nitin@nitin-Ideapad-Z570:~$ curl http://passtms.in/vimal.cgi <html> <head> <title>Hello Word - First CGI Program</title> </head> <body> <h2>Hello Word! This is my first CGI program</h2> <p>2.7.6 (default, Jun 22 2015, 17:58:13) [GCC 4.8.2]</p> First name: <input type="text" name="fname"><br> </body> </html> nitin@nitin-Ideapad-Z570:~$ In the first instance also it the same : -------------------------------------------------------------- #!/usr/bin/env python import sys import cgi import psycopg2 print "Content-type:text/html\r\n\r\n" print '<html>' print '<head>' print '<title>Hello Word - First CGI Program</title>' print '</head>' print '<body>' print '<h2>Hello Word! This is my first CGI program</h2>' print "<p>"+ sys.version + "</p>" print 'First name: <input type="text" name="fname"><br>' print '</body>' print '</html>' output (below):- nitin@nitin-Ideapad-Z570:~$ curl http://passtms.in/vimal.py <html> <head> <title>Hello Word - First CGI Program</title> </head> <body> <h2>Hello Word! This is my first CGI program</h2> <p>2.7.6 (default, Jun 22 2015, 17:58:13) [GCC 4.8.2]</p> First name: <input type="text" name="fname"><br> </body> </html> On 20 July 2016 at 15:15, Peter Otten <__pete...@web.de> wrote: > nitin chandra wrote: > >> On inserting the line ... >> >> print "<p> + "sys.version + "</p>" >> >> required slight correction >> >> print "<p>" + sys.version + "</p>" >> >> and the following script and its output are below :- >> ---------------------------------------- >> #!/usr/bin/env python >> >> import sys >> import cgi >> import psycopg2 >> >> print "Content-type:text/html\r\n\r\n" >> print '<html>' >> print '<head>' >> print '<title>Hello Word - First CGI Program</title>' >> print '</head>' >> print '<body>' >> print '<h2>Hello Word! This is my first CGI program</h2>' >> print "<p>"+ sys.version + "</p>" >> print 'First name: <input type="text" name="fname"><br>' >> print '</body>' >> print '</html>' >> >> --------------------------------------------------- >> >> Hello Word! This is my first CGI program >> >> 2.7.6 (default, Jun 22 2015, 17:58:13) [GCC 4.8.2] >> >> First name: > > If you got that from your server like in the session below... > > $ cat first.py > #!/usr/bin/env python > > import sys > import cgi > import psycopg2 > > print "Content-type:text/html\r\n\r\n" > print '<html>' > print '<head>' > print '<title>Hello Word - First CGI Program</title>' > print '</head>' > print '<body>' > print '<h2>Hello Word! This is my first CGI program</h2>' > print "<p>"+ sys.version + "</p>" > print 'First name: <input type="text" name="fname"><br>' > print '</body>' > print '</html>' > $ curl http://myhost/somewhere/first.py > > <html> > <head> > <title>Hello Word - First CGI Program</title> > </head> > <body> > <h2>Hello Word! This is my first CGI program</h2> > <p>2.7.6 (default, Jun 22 2015, 17:58:13) > [GCC 4.8.2]</p> > First name: <input type="text" name="fname"><br> > </body> > </html> > > ... the following should also work: > > $ cat second.py > #!/usr/bin/env python > > import sys > import cgi > import psycopg2 > > print """Content-type:text/html\r\n\r\n > <html> > <head> > <title>Hello Word - First CGI Program</title> > </head> > <body> > <h2>Hello Word! This is my first CGI program</h2> > <p>{version}</p> > First name: <input type="text" name="fname"><br> > </body> > </html> > """.format(version=sys.version) > $ curl http://myhost/somewhere/second.py > > <html> > <head> > <title>Hello Word - First CGI Program</title> > </head> > <body> > <h2>Hello Word! This is my first CGI program</h2> > <p>2.7.6 (default, Jun 22 2015, 17:58:13) > [GCC 4.8.2]</p> > First name: <input type="text" name="fname"><br> > </body> > </html> > > If it does you can start looking for the actual problem. I don't expect it > to have anything to do with your choice of quoting characters, as long as > you write legal Python 2. > > _______________________________________________ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor