So I've been developing using PHP and mainly working on WordPress sites. I need to learn python at the moment. I've read online a lot, and although they provide easy tutorials on how to learn the language of python, I need to learn how to get started with its development on my local machine's MAMP server.
Usually for PHP I'd dump an index.php file into the htdocs folder and navigate to it using the URL and it works. I know PHP is the easiest to deploy, as I've learned ASP.NET at university. For Python, though, I've read about the cgi-bin and how MAMP already has mod_wsgi and mod_python installed. I'm not quite familiar with such terms and not familiar with how to start using it on MAMP. I need to know how I can run a website using python. Learning the language is easy, since I can google it myself from hereon and then go for Django.
For example, it would output hello world if I used this piece of code:
def application(environ, start_response):
status = '200 OK'
output = 'Hello World!'
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]
However, this code gives me an error:
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# enable debugging
import cgitb
cgitb.enable()
print "Content-Type: text/plain;charset=utf-8"
print
print "Hello World!"
Said error showing up in the logs is:
mod_wsgi (pid=1794): Target WSGI script '/Applications/MAMP/htdocs/test/index.py' does not contain WSGI application 'application'.
As you can see I'm oblivious to what happened there. I didn't touch any MAMP configuration files, yet.
TL;DR: I want to know how to open up a simple Python generated page on my local MAMP server. I have no idea how it works. Where do I go to learn? (I don't want to learn the language, yet)
$ python my_script.py, then open your browser. Look at Tornado for a simple Python web server/framework to get started for example.