You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Simon Hook <si...@jpl.nasa.gov> on 2005/03/10 07:23:12 UTC
[users@httpd] When an image is replaced in the htdocs directory through a cgi script
and incorporated into a new html page the new image does not get incorporated.
PROBLEM: When an image is replaced in the htdocs directory through a cgi
script and incorporated into a new html page the new image does not get
incorporated.
Hi All,
I am trying to write a web app where a variable, passed with a form, is
used to generate a plot, which is saved and then displayed as a static
image in an html page. I am using the webform from pythonweb and
generating the plot with matplotlib. I am using Apache 2.053 under
Windows XP. I am keeping it real simple by simply passing an integer.
The whole process works, HOWEVER, when I back page and submit a new
integer value which generates a new plot and new static image, the new
image does not get displayed, instead the last version of the static
image (plot) is displayed (presumably from the cache). If I reload the
page with the browser the updated image gets displayed otherwise the
previous plot gets displayed with 2 or 3 re-submits and then eventually
an updated one is displayed. It seems like Apache does not recognize a
changed image and still uses the first plot I created for 2 or 3 submits
or the submit does not force Apache to look for a changed file.
I am new to Apache, Pythonweb and MatplotLib although I have done
similar stuff with ASP and IIS and some Python work. I have waded
through the Apache and Pythonweb documentation and got nowhere. I have
tried using the MOD_EXPIRES directive with Apache but this has no
effect. I think this is because a new image (PNG) has been generated
rather than an old one has expired. I cannot see any way with pythonweb
forms to load a static html page (i.e. with cgi). I think if I had a
static html page I could write out maybe I could expire that which would
force Apache to load the new image file.
I have tried
<META HTTP-EQUIV=Refresh CONTENT=1>
which refreshes the page every second - this works but who would want it!
I have tried
<META HTTP-EQUIV=expires CONTENT=0>
but this does not work.
I have attached the code below, its a rework of one of the examples in
pythonweb. Just copy this to the cgi-bin directory and it should work,
provided matplotlib is installed. Matplotlib is available from:
http://matplotlib.sourceforge.net/
Pythonweb is available from:
http://www.pythonweb.org
Despite hours of trying I cannot get this to work, which would seem like
a necessity for Pythonweb and Apache. Any help would be much appreciated.
Thanks,
Simon
---cut here
#!d:/apps/Python23/python
"The form that will not update"
import sys, re, os
sys.path.append('../')
sys.path.append('../../')
import web.error; web.error.handle(handler='browser', output='debug',
format='html')
import web, web.form, web.form.field.basic, web.util
import web.form.field.typed
from pylab import *
class ExampleForm(web.form.Form):
def setup(self):
self.addField(web.form.field.typed.Integer('myval', default=6,
required=True))
# The preffered way of adding submit buttons is as actions so
Submit buttons are normally not used.
self.addAction('Validate This Form')
# Print the HTTP Header
print web.header('text/html')
# Create a form
exampleForm = ExampleForm('form', os.environ['SCRIPT_NAME'], 'get')
if len(web.cgi) > 0: # Form submitted
# Populate form with the values from get.
# Populate the form
exampleForm.populate(web.cgi)
# Process the form (Validate)
if exampleForm.valid():
# Grab the desired value, from the form
myval=exampleForm['myval'].value
# Create the plot, saved as a png in the htdocs directory
myarray=[myval,4,9,16]
print myarray
plot([1,2,3,4], myarray, 'ro')
axis([0, 6, 0, 20])
savefig('../htdocs/plot.png')
print "<hmtl><body><div align=center><img src=/plot.png
alt=theplot></div></body></html>"
else:
print "<html><head><title>noupdate</title></head><body>\n<h1>Input
integer 0-10</h1>%s\n<hr></body></html>"%(exampleForm.html())
---end cut
---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org