Windows – Running Python scripts in a browser

mod-wsgipythonwindows

I want to start learning Python – and I'm having trouble getting scripts to load up in a browser (using Wamp). So far I've tried the following:

1: add the following lines to httpd.conf:

AddHandler cgi-script .py
Options ExecCGI

I navigate to

http://localhost/path/to/script/myscript.py
  • but get an Internal Server error.

2: downloaded mod_wsgi-win32-ap22py26-3.0.so
– renamed to mod_wsgi (running Wamp with Apache 2.2)
added the following lines to httpd.conf

AddHandler mod_wsgi .py
WSGIScriptAlias /wsgi/ "path/to/my/pythonscripts/folder/"

but when I navigate to the script at

http://localhost/wsgi/script.py
  • it renders the script in it's entirety i.e.

    !c:/Python26/python.exe -u

    print "hello world"

I managed to get CherryPy working, but ideally I want to learn the language in a relatively raw context before digging into a framework. Can anyone give me some pointers?

Best Answer

You're mixing your goals. if you

want to learn the language in a relatively raw context before digging into a framework

then forget about the browser for a while.

Open a text editor, a command window and the interpreter (or a nice shell on the interpreter, like ipython). When you get the hang of the language, and what does it do, and how, then (and only then) start using it to create web pages.

When you get to the web environment, using a framework is optional. You can simply build HTML to stdout, and be called like CGI, or fire up a wsgi server and write wsgi handler functions, or Cherry py, to simply attach functions to URLs, or go full stack with Django, where you define classes and other setups to describe your infrastructure (database model, html forms, template tags, etc), and then (again) attach functions to URLs