[mod_python] When I try to use include directive an SyntaxError error occurs

Jim Gallacher jpg at jgassociates.ca
Mon Apr 10 16:45:55 EDT 2006


Mikhail wrote:
> Salut, Jim.

Salut Mikhail,

Please keep the conversation on the mailing list.

> 
>>>tst3.psp content:
>>>
>>><html>
>>><%
>>>import time
>>>%>
>>>Hello world, the time is: <%=time.strftime("%Y-%m-%d, %H:%M:%S")%><br>
>>><%
>>>%>
>>><% include file="tst4.psp"%>
> 
> 
> JG> Missing '@' perhaps?
> 
> JG> <%@ include file="tst4.psp"%>
> JG> ^^^
> 
> No, with '@' this directive include nothing.
> This thread not help me:
> http://www.modpython.org/pipermail/mod_python/2005-March/017589.html

If you want to include a psp file you must use it, otherwise the parser 
expects to find a valid python statement which is clearly not the case here.

I took a look at your original email and I think you are chasing the 
wrong problem, as you never actually render the page. Your index.py 
should look like this:

from mod_python import apache, psp, util, Cookie, Session

def index(req):
     # It always a good idea to set the content type
     # for browsers like Firefox
     req.content_type = 'text/html'
     filename = "tst3.psp"
     template = psp.PSP(req, filename)
     # render the page!
     template.run()
     return apache.OK


Also, there is an error in your apache config, but I think it is just a 
typo in your message, otherwise you wouldn't even get the parse error.

# Wrong
PythonHandler index:index

# Right
PythonHandler index::index

Everything should work once you make these changes, including the '@' 
character.

<%@ include file="tst4.psp"%>

Jim




More information about the Mod_python mailing list