Jump to content

Using Python For Cgi


minus11

Recommended Posts

Hi all,

 

I am trying to write my first CGI script using Python on my shared virtual web server. I put the script under 'public_html' in the 'cgi-bin' folder on my web server. I made the script executable with the chmod +x command. For the she-bang I am using #! /usr/bin/env python so that the script will be able to find any Python interpreter and not a specific one at a specific location.

 

I made a test form to call the script from when a button is clicked but I just receive a 500 Internal Server error when trying to run this script. I messed around some with the location of the cgi script, which is a .py file in this case, but only received 404 errors.

 

Does anyone reading this know what I am missing?

 

Here is my Python script:

 

#! /usr/bin/env python
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 third or fourth or so CGI program</h2>'
print '</body>'
print '</html>'

 

 

Here is my HTML code that calls the Python script:

 

<!DOCTYPE html>
<head>
<title>Test CGI Scripting With Python</title>
</head>
<body>
<center>
<form action="cgi-bin/hello.py" method="post">
Click this button
<input type="submit" value="Submit" />
</form>
</center>

</body>
</html>

 

 

Thank-you for reading this everybody. :D

 

Respectfully,

 

minus

Link to comment
Share on other sites

  • 3 weeks later...
  • 1 month later...
  • 1 month later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...