【问题标题】:Python + Apache web pages not updatingPython + Apache 网页未更新
【发布时间】:2014-12-28 17:06:31
【问题描述】:

我有用于 python 页面的带有 WSGI 模块的 apache 服务器。

我有带有 str(datetime.datetime.now()) 的 index.wsgi 文件,它打印当前时间戳。
问题是当我刷新页面时,我看不到它更新,它会在几秒之间跳转,看起来缓存中有 3-4 个旧结果并且正在显示它们..

我试图查看它是否在网络浏览器上使用缓存但找不到任何东西..

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>

有什么想法吗?!

谢谢。

【问题讨论】:

  • 你能显示你的 index.wsgi 文件吗?
  • ...以及 Apache 主机配置的相关部分,可能还有网络服务器响应的标头。

标签: python apache wsgi


【解决方案1】:

您的 body 变量是全局变量,这意味着它会在流程开始时进行评估,并且永远不会重新计算。您在几个不同的值之间切换的原因是 Apache 启动了几个单独的进程:每个进程都有自己的 body 值,该值将持续到进程重新启动,并且不同的请求被路由到不同的进程。

不要将 body 变量放在全局级别,而是从应用程序函数调用的函数中返回它。

【讨论】:

  • 有效!非常感谢!我花了 2 天时间.. :)
猜你喜欢
  • 1970-01-01
  • 2021-07-25
  • 2012-06-26
  • 1970-01-01
  • 1970-01-01
  • 2019-08-25
  • 2020-05-04
  • 2015-10-08
  • 2016-09-24
相关资源
最近更新 更多