#!D:\Python27\python.exe
print 'Content-Type: text/html'
print '<html>'
print '<head><title>Hello Python</title></head>'
print '<body>'
print '<h1>Hello Python</h1>'
print '</body>'
print '</html>'
AddHandler mod_python .py
PythonHandler mod_python.publisher
PythonDebug On
<html>
Please provide feedback below:
<p>
<form action="form.py/email" method="POST">
Name: <input type="text" name="name"><br>
Email: <input type="text" name="email"><br>
Comment: <textarea name="comment" rows=4 cols=20></textarea><br>
<input type="submit">
</form>
</html>
import smtplib
WEBMASTER = "webmaster" # webmaster e-mail
SMTP_SERVER = "localhost" # your SMTP server
def email(req, name, email, comment):
# make sure the user provided all the parameters
if not (name and email and comment):
return "A required parameter is missing, \
please go back and correct the error"
# create the message text
msg = """\
From: %s
Subject: feedback
To: %s
I have the following comment:
%s
Thank You,
%s
""" % (email, WEBMASTER, comment, name)
# send it out
conn = smtplib.SMTP(SMTP_SERVER)
conn.sendmail(email, [WEBMASTER], msg)
conn.quit()
# provide feedback to the user
s = """\
<html>
Dear %s,<br>
Thank You for your kind comments, we
will get back to you shortly.
</html>""" % name
return s
<Directory /mywebdir>
AddHandler mod_python .py
PythonHandler myscript
PythonDebug On
</Directory>
from mod_python import apache
def handler(req):
req.content_type = "text/plain"
req.write("Hello World!")
return apache.OK
AddHandler mod_python .psp
PythonHandler mod_python.psp
<html>
<%
import time
%>
Hello world, the time is: <%=time.strftime("%Y-%m-%d, %H:%M:%S")%>
</html>
import os
os.environ['PYTHON_EGG_CACHE'] = '/usr/local/trac/mysite/eggs'
import trac.web.main
def application(environ, start_response):
environ['trac.env_path'] = '/usr/local/trac/mysite'
return trac.web.main.dispatch_request(environ, start_response)
WSGIScriptAlias /trac /usr/share/trac/cgi-bin/trac.wsgi
<Directory /usr/share/trac/cgi-bin>
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
<%inherit file="base.html"/>
<%
rows = [[v for v in range(0,10)] for row in range(0,10)]
%>
<table>
% for row in rows:
${makerow(row)}
% endfor
</table>
<%def name="makerow(row)">
<tr>
% for name in row:
<td>${name}</td>\
% endfor
</tr>
</%def>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:py="http://genshi.edgewall.org/"
xmlns:xi="http://www.w3.org/2001/XInclude">
<head>
<title>Available Projects</title>
</head>
<body>
<h1>Available Projects</h1>
<ul>
<li py:for="project in projects" py:choose="">
<a py:when="'href' in project" href="$project.href" title="$project.description">$project.name</a>
<py:otherwise>
<small>$project.name: <em>Error</em> <br /> ($project.description)</small>
</py:otherwise>
</li>
</ul>
</body>
</html>
<title>{% block title %}{% endblock %}</title>
<ul>
{% for user in users %}
<li><a href="{{ user.url }}">{{ user.username }}</a></li>
{% endfor %}
</ul>