page contents are not refreshed

waylan waylan at gmail.com
Wed Sep 13 15:06:45 EDT 2006


Gleb Rybkin wrote:
> when running apache, mod_python in windows.
>
> This looks pretty strange. Creating a simple python file that shows
> current time will correctly display the time in apache the first time,
> but freezes afterwards and shows the same time on all subsequent clicks
> as long as the file is not modified.
>
> Any ideas what's wrong? Thanks.

The first time the page was requested mod_python compiled and loaded
your code. Every request after that mod_python refers to the already
loaded code in memory in which your expression had already been
evaluated the first time.

Therefore, you need to make curtime a 'callable object' so that it will
be re-evaluated on each request. Unfortunelty, I don't recall if simply
wraping your strftime() expression in a function will be enough or if
its more complex that that. That said, I **think** this should work:
>
> from mod_python import apache
> from time import strftime, gmtime
>
def curtime():
    return strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime())

> def handler(req):
>      req.content_type = "text/plain"
>      req.send_http_header()
>      req.write(str(curtime()))
>      return apache.OK




More information about the Python-list mailing list