HOWTO: Colorizing your Python source code on Apache

Here I will explain how to create a directory on your Apache web server, where every Python source code gets sintax highlighting when accessing it using a web browser.

(1) Download colorize.py
(2) Create the desired directory, ie http://www.yoursite.com/code/
(3) Upload the colorize.py file to the directory and rename it to colorize.cgi
(4) Give execution permissions to the colorize script
(5) Create a .htaccess file on the directory with this code inside:
AddHandler application/x-python .py
Action application/x-python http://www.yoursite.com/code/colorize.cgi

That’s all! Now, when you upload a .py file to this directory, when accesing it via web, you will see the file with sintax highlighting!

Example here: http://www.infinicode.org/code/

Leave a Reply