Python + Apache web pages not updating
Question: I have apache server with WSGI module for python pages.

I have index.wsgi file with str(datetime.datetime.now()) which print the
current timestamp.  
The issue is when I am refreshing the page I cannot see it updates, it jumps
between seconds or something, looks like it has 3-4 old results in the cache
and it is showing them..

I tried to see if it use cache on the web browser but could not find
anything..

index.wsgi:

    
    
    #!/usr/bin/python
    # -*- coding: UTF-8 -*-
    
    import datetime
    
    html="""
    <HTML>
    <HEAD><TITLE>Manual Runner</TITLE>
    <BODY>
    timestamp: {0}<BR><BR>
    </BODY></HTML>
    """.format(str(datetime.datetime.now()))
    
    
    def application (env, r):
        body = html
        status = '200 OK'
        response_headers = [ ('Content-Type', 'text/html'), ('Content-Length', str (len (body) ) ) ]
        r (status, response_headers)
        return [body]
    

httpd.conf:

    
    
    WSGIScriptAlias / /web_manager/manual_run/index.wsgi
    
    <Directory /web_manager/manual_run>
    Order allow,deny
    Allow from all
    Options +ExecCGI
    AddHandler cgi-script .py
    DirectoryIndex index.wsgi
    </Directory>
    

Any idea?!

Thanks.


Answer: Your body variable is global, which means it is evaluated when the process
starts, and is never recalculated. The reason you flip between a few different
values its that Apache has started a few separate processes: each will have
its own value for body, which will persist until the process is restarted, and
different requests are being routed to different processes.

Instead of putting the body variable at global level, return it from a
function which is called from your application function.

