Python WebDev from scratch – WSGI (cont.)

In my previous post, I talked about how to enable mod_wsgi in apache. In this post I’m going to give brief information about, how to make apache to process .py files like it is processing .php files? You probably know that apache, (using mod_php), handles every requests to the webserver (port 80), and call the scripts that the client wants from it. We are going implement somewhat same system for python (using mod_wsgi), like this. Firstly, add following to the top of your httpd.conf file:

WSGIScriptAlias /app /var/www/app/wsgi-scripts/home.wsgi

In this path, everything is optional. The main idea is to add some WSGI alias named /app, and pointing to the .wsgi file in “/var/www/app/wsgi-scripts/”. That’s all, nothing fancy there. ;)

And, restart the apache:

$ sudo /etc/init.d/apache2 restart


You’re done now. You can create your wsgi application, in the directory which you told apache about, and create some “routes”, “urls” and etc. From now on, your webserver will be your “.wsgi” file. In this file you’re going to add “RewriteRules“, “Options” like in apache, but more pythonly and regexply. You can find more info here. Have fun with WSGI :)

part1