Personal tools


From MohidWiki

Jump to: navigation, search

Mod-python is a module for the apache web server that allows to run python scripts and publish html.


Edit /etc/httpd/conf.d/python.conf or the /etc/httpd/conf/httpd.conf

LoadModule python_module modules/

<Directory /var/www/html/python>
   AddHandler mod_python .py
   PythonHandler mod_python.publisher
   PythonDebug On

You can also add the following lines in the .htaccess file from the local user's public_html directory:

   AddHandler mod_python .py
   PythonHandler mod_python.publisher
   PythonDebug On



  <title>A simple "get month" script</title>
  <form method="POST" action="python/">
  Show which month for 2005
  <select name="month">
     <option value="1">January</option>
     <option value="2">February</option>
     <option value="3">March</option>
     <option value="4">April</option>
     <option value="5">May</option>
     <option value="6">June</option>
     <option value="7">July</option>
     <option value="8">August</option>
     <option value="9">September</option>
     <option value="10">October</option>
     <option value="11">November</option>
     <option value="12">December</option>
  <input type="submit" value="Show Month">


#!/usr/bin/env python
# A simple script to output a calendar month based off input
# from a web form.
import calendar
from mod_python import apache
def getMonth(req,month):
   req.write(calendar.month(2005, int(month),2,3))


 """ Publisher example """
 def say(req, what="NOTHING"):
     return "I am saying %s" % what