Entry
How do I use python code in ASP tags?
Mar 1st, 2000 22:04
Nathan Wallace, Tom Funk
There are a couple of things you might want to check:
That the Win32 Python Extensions are properly installed.
Your Python version is 1.5.2.
<%@Language=Python%> as the first executable line in the ASP file.
Between the <% %> delimiters, leading spaces are important. For
instance:
<%
import sys
pyVersion = sys.version
%>
will work. Whereas
<%
import sys
pyVersion = sys.version
%>
will fail. The interpreter doesn't like the leading spaces in front of
import and pyVersion.
Here's a sample ASP file that should work as-is (it works for me). Copy
and paste it into an ASP file and execute it from your server. It
should
display the current Python version and a list of server environment
variables.
If this doesn't work, your Win32 Extensions installation may be hosed
up.
-----------[ copy after this line ]--------------
<%@Language=Python%>
<html>
<body>
<%
# NO leading spaces here
indent = " " * 5
def emitEnv():
# leading spaces needed here...
import os
for key in os.environ.keys():
Response.Write("<br>%s<b>%s</b>=%s\n" %
(indent, key, os.environ[key]))
# again, NO leading spaces here
import sys
pyVersion = sys.version
%>
<h3>Current Python Version</h3>
<p><%=indent + pyVersion%></p>
<h3>Server Environment Variables</h3>
<%
# no leading spaces, yet again
emitEnv()
%>
<body>
<html>
-----------[ copy before this line ]--------------