So I installed python on my server and I’m using the wsgi_module with apache.
Do all my python programs have to use this format:
def application(environ, start_response):
headers = []
headers.append(('Content-Type', 'text/plain'))
write = start_response('200 OK', headers)
input = environ['wsgi.input']
output = cStringIO.StringIO()
print >> output, "test"
output.write(input.read(int(environ.get('CONTENT_LENGTH', '0'))))
return [output.getvalue()]
Is there anyway to set it up so I can write python scripts and just have:
print "test"
Yes, your script certainly need to have callable (not necessarily a function, it can also be a class with __call__ method defined) that accepts environ and *start_response* arguments as it is a part of wsgi standard and that is the way how it works.
The way you’d like to write scripts in PHP-style like “print something” doesn’t work. There’s a currently dead initiative called initially PSP (Python Server Pages) that mixed up code and templates, but it couldn’t gain popularity as it’s certainly not a Python-way of writing applications.