Python
Python tips.
Server error!
Getting python to spit out html-like files isn't too hard, but remembering all of the details can be a pain. This is a quick checklist of things that might be wrong when you get the dreadfully helpful HTTP Error 500.
- Assuming you're on Apache, make sure the
.htaccessis set up to execute python files. The magic words are
Options +ExecCGI
AddHandler cgi-script .py - chmod so the server can actually execute the file.
- make sure there are no straight-up python errors by running it in the terminal. At the very least, you can see if there are syntax errors
- You need a content header so the browser knows what it's looking at.
print 'Content-Type: text/html;\n\n'(modified to fit the content-type). Remember this must be the first thing it prints. - Sometimes python can help with Server Error pages. In your python file, say
import cgitb
cgitb.enable() - The first line should be a shebang, like
#!/usr/bin/python. For your particular setup, you can find this by typing into the terminalwhere python.
Woot. Back to funtimes.
Comments