Python 101
Koshimi said:
Just a couple of things. When using python cgi you need to import the cgi module also because you are working with web documents you need to tell what type of document header it needs to use.
So... The code will look as follows:
Code:
#!/usr/bin/env python
import cgi
print "Content-type: text/html"
print
print "Hello World"
Line 1: The shebang (#!/usr/bin/env python) - this line uses the env command some times python is not installed in /usr/bin. This command looks in several location for a python installation.
Line 3: Import the cgi module so that it can be use via the web.
Line 5 + 6: Here we tell the browser that the page is text and formated as html the secont print command seperates the header from the reast of the script. With out it the script fails.
Line 7: We print
Hello World
Using python out side cgi-bin
If you want to use python files outside cgi-bin or use the .py file extention you need to goto
Apache Handlers in cPanel can add
.py (or any other extention) and
cgi-script in the two boxes provided. This will allow you to execute cgi files anywhere on your site (BTW: .cgi is set by default).
For those in still think you can use ASP.net in linux
http://www.mono-project.com/ASP.NET
PS (Koshimi): I added two extra files for you to look at. One lists the environment variables the other is a simple form.
PPS (Koshimi): Do you really want your username changed?