I would like to create web page which will print simple message
x minutes to shutdown
where 'x' would decrease once a minute automatically without clicking 'refresh' in web browser. The value will be counted from data downloaded from SNMP source (that is why I wanted to use Python). AFAIK I should use Java开发者_StackOverflowscript (am I right ?).
Is it possible to use Python to this sort of task (dynamic web page)? If not what other language would you suggest ?
You could use a scripting language of your choice to load the initial time on the server side, and just serve your page with a Javascript timer that modifies the time every minute.
You would need to look into the setTimeout()
Javascript function to manage the timer.
Something like this:
<script type="text/javascript">
var timer = setTimeout ( "changeTime()", 60000 );
function changeTime(){
//modify time logic
clearTimeout ( timer );
timer = setTimeout ( "changeTime()", 60000 );
}
</script>
Javascript is the only language the works well on the web. So yes, you have to use it.
Not very Web 2.0, and also discouraged by the W3C, but you could add this to your HTML header:
<meta http-equiv="refresh" content="60" />
That will automatically refresh the page for you every 60 seconds without the user having to click refresh.
To implement this you would create a CGI script using Python, which gets the result via SNMP and generates the webpage with your message. If this script also outputs the meta refresh above, it will be updated by the browser every minute, generating the new content.
The proper way of doing this is probably using AJAX. It all depends on how much time you want to spend on it.
精彩评论