473,795 Members | 2,867 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dynamic HTML from Python Script

I have a python script whose output i want to dynamically display
on a webpage which will be hosted using Apache. How do I do that?
thanks
Jun 27 '08
14 5415
On Jun 11, 1:58 am, asdf <a...@asdf.comw rote:
I have a python script whose output i want to dynamically display
on a webpage which will be hosted using Apache. How do I do that?

thanks
def index(req):
return "Page"

u cant run it on lighttpd also, which is much faster then Apache :P
Jun 27 '08 #11
Lie
On Jun 11, 9:57*am, Aidan <awe...@gmail.c omwrote:
asdf wrote:
On Wed, 11 Jun 2008 11:20:48 +1000, Aidan wrote:
asdf wrote:
Well, there's a few ways you could approach it.
>>You could create a cgi program from your script - this is probably the
solution you're looking for.
>Output from the script does come up very often. There is a new output
every 10 secs and it's possible that the script might be run
indefinitely . Basically I want all that output displayed in a web
browser
Well, in that case you could simply append the new output to a static
file every 10 seconds, or whenever there is new output. *That way, you
just need to refresh the static file in your browser to see updates...
Given what I understand of your situation, that's how I'd do it.
The problem with this is that browser would have to be refreshed manually
every 10 seconds. Unless there is a way to set this in the script itself..

You should be able to do that with just:

<meta http-equiv="refresh" content="10"/>

in the <headsection of your page (you can adjust the value of content
from 5 to however many seconds you want between refreshes).
That's an alternative way although many older browser doesn't support
it, it's probably a better way instead of using Javascript if you
don't care about those that are using old browser.
You could also look at adding some AJAX-yness to your page, and have it
query your script for new output every 10 seconds, and then add that
content to the existing page... it sounds like this behavior is what
you're looking for, but it's slightly harder to pull off than the method
mentioned above.
FYI: AJAX is just a very fancy name for Javascript
>
A constantly running CGI app is probably not the best idea, given
timeouts and other such constraints you might run into.
>>You could have the script run periodically and create a static html
file in the webroot... this would be acceptable, maybe preferable, if
the output from your script doesn't change frequently.

Jun 27 '08 #12
On Jun 11, 7:59 am, Lie <Lie.1...@gmail .comwrote:
You can't make the browser refresh automatically in the server side,
Yes you can. I don't know how to do it in Python, but here's an
example in Flaming Thunder of a small, fast, light compiled server
side CGI that delivers dynamic content every 10 seconds.

# Write out the HTTP headers, followed by a blank line.
# Make sure to write CRLF and not just LF, as per HTTP
# specs. Also, turn off caching using the no-cache and
# expires options, so that caching doesn't conflict with
# refreshes.

Set CRLF to CarriageReturn+ LineFeed.
Write "Refresh: 10; url=http://www.flamingthun der.com/cgi/
refresh.cgi",CR LF.
Write "Content-type: text/html",CRLF.
Write "Pragma: no-cache",CRLF.
Write "Expires: 0",CRLF.
Write "Cache-Control: no-cache",CRLF.
Write CRLF.

# Write out the dynamic information. In this
# case, we'll just write out Greenwich mean time.

Write GetGreenwichMea nTime.

For this example, the dynamic content is just Greenwich mean time.
You can see it in action at:

http://www.flamingthunder.com/cgi/refresh.cgi

To create the CGI script, I used Flaming Thunder's cross compiling
ability to compile the script under Windows, targeting Linux:

ft file refresh.ft output refresh.cgi target linux32

I then ftp'd refresh.cgi up to the cgi directory on my server, set the
permissions to 700 to make it executable, and it works (without
needing to install any bulky, plodding interpreter).

On Jun 11, 7:59*am, Lie <Lie.1...@gmail .comwrote:
On Jun 11, 9:16*am, asdf <a...@asdf.comw rote:


On Wed, 11 Jun 2008 11:20:48 +1000, Aidan wrote:
asdf wrote:
>>Well, there's a few ways you could approach it.
>>You could create a cgi program from your script - this is probably the
>>solution you're looking for.
>Output from the script does come up very often. There is a new output
>every 10 secs and it's possible that the script might be run
>indefinitely . Basically I want all that output displayed in a web
>browser
Well, in that case you could simply append the new output to a static
file every 10 seconds, or whenever there is new output. *That way, you
just need to refresh the static file in your browser to see updates...
Given what I understand of your situation, that's how I'd do it.
The problem with this is that browser would have to be refreshed manually
every 10 seconds. Unless there is a way to set this in the script itself..

Surely you don't think you can do that without Javascript don't you?
You can't make the browser refresh automatically in the server side,
it has to be done in the client side scripting or like Opera browser
that have an option to make it refresh a page every few seconds.
A constantly running CGI app is probably not the best idea, given
timeouts and other such constraints you might run into.
>>You could have the script run periodically and create a static html
>>file in the webroot... this would be acceptable, maybe preferable, if
>>the output from your script doesn't change frequently.- Hide quoted text -

- Show quoted text -- Hide quoted text -

- Show quoted text -
Jun 27 '08 #13
Lie <Li******@gmail .comat Mittwoch 11 Juni 2008 16:04:
FYI: AJAX is just a very fancy name for Javascript
AJAX is not just a "name", it's a _religion_

SCNR

--
Freedom is always the freedom of dissenters.
(Rosa Luxemburg)
Jun 27 '08 #14
On Jun 11, 10:43 pm, Dennis Lee Bieber <wlfr...@ix.net com.comwrote:
Those are not /server side/ refreshes...
Correct. But we weren't discussing server side refreshes. We were
discussing how to make the "browser refresh automatically in the
server side":

On Jun 11, 7:59 am, Lie <Lie.1...@gmail .comwrote:
Surely you don't think you can do that without Javascript don't you?
You can't make the browser refresh automatically in the server side,
it has to be done in the client side scripting or like Opera browser
that have an option to make it refresh a page every few seconds.
The example I posted showed a simple way to "make the browser refresh
automatically in the server side" by using an HTTP Refresh header
instead of using any Javascript or client side scripting or setting a
browser option to refresh the page every few seconds.
On Jun 11, 10:43*pm, Dennis Lee Bieber <wlfr...@ix.net com.comwrote:
On Wed, 11 Jun 2008 07:36:59 -0700 (PDT), Dave Parker
<davepar...@fla mingthunder.com declaimed the following in
comp.lang.pytho n:
Yes you can. *I don't know how to do it in Python, but here's an
example in Flaming Thunder of a small, fast, light compiled server
side CGI that delivers dynamic content every 10 seconds.
* # Write out the HTTP headers, followed by a blank line.
* # Make sure to write CRLF and not just LF, as per HTTP
* # specs. *Also, turn off caching using the no-cache and
* # expires options, so that caching doesn't conflict with
* # refreshes.
* Set CRLF to CarriageReturn+ LineFeed.
* Write "Refresh: 10; url=http://www.flamingthun der.com/cgi/
refresh.cgi",CR LF.

* * * * Those are not /server side/ refreshes... The first thing being
written is a command to the browser that tells the browser to reload the
specified page after a delay period.

* * * * IOWs it is the browser doing the refresh -- which means itstarts a
whole new connection, receiving a page from the CGI script... Said page
again having a browser command to do a delayed refresh.

* * * * Server side would mean that the server somehow continuously sends
updates WITHOUT BEING ASKED.
--
* * * * Wulfraed * * * *Dennis Lee Bieber * * * * * * * KD6MOG
* * * * wlfr...@ix.netc om.com * * * * * * *wulfr...@besti aria.com
* * * * * * * * HTTP://wlfraed.home.netcom.com/
* * * * (Bestiaria Support Staff: * * * * * * * web-a...@bestiaria. com)
* * * * * * * * HTTP://www.bestiaria.com/
Jun 27 '08 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2033
by: Whitney Battestilli | last post by:
I'm trying to embed python into an application that already contains a scripting language. This scripting language contains thousands of commands and I have the ability to query the script engine and get syntax information regarding valid arguments and such. Rather than writing explicate wrappers for each command (which will be very time consuming), I would like to extend python by creating a module that allows any function name to be...
13
2899
by: mr_burns | last post by:
hi, is it possible to change the contents of a combo box when the contents of another are changed. for example, if i had a combo box called garments containing shirts, trousers and hats, when the user selects shirts another combo box called 'size' would contain sizes in relation to shirts (ie. chest/neck size). the same would occur for trousers and hats. when the user selects an option in the garment combo box, the options available...
2
3103
by: Keith Burns | last post by:
Hi, I have seen two entries in the archives for this topic: 1. Uses hypertext, not a pulldown menu to feed parameters back to the python CGI 2. The other actually used Java. Is there a way using Python for CGI such that when a user selects an item from one pull down menu (ie FRUIT or VEGETABLE or MEAT) that another pull
8
2257
by: Sandy Pittendrigh | last post by:
I have a how-to-do-it manual like site, related to fishing. I want to add a new interactive question/comment feature to each instructional page on the site. I want (registered) users to be able to add comments at the bottom of each page, similar to the way the php, mysql, apache manuals work. PUNCHLINE_A:
8
5374
by: hyejin | last post by:
I have a problem with dynamic iframe and document.close() on Firefox. Below two files create a dynamic iframe by JavaScript. These two samples do not have any problems on IE. But, on Firefox, the icon on the top corner keeps running with "loading" message on the bottom status bar even though the browser completed everything in the iFrame. The line that causes the problem is "document.close()" in the included JS file. If this line is...
10
4939
by: jflash | last post by:
Hello all, I feel dumb having to ask this question in the first place, but I just can not figure it out. I am wanting to set my site up using dynamic urls (I'm assuming that's what they're called, an example of what I have in mind is index.php?page=). However, I can not figure out how to do this. I will eventually want to use SEF urls, but for now I'll be content just to have the dynamic urls. If anyone can tell me how to do this, I'd...
9
2986
by: pbd22 | last post by:
Hi. This is just a disaster management question. I am using XMLHTTP for the dynamic loading of content in a very crucial area of my web site. Same as an IFrame, but using XMLHTTP and a DIV. I got the core of the javascript from here: http://www.dynamicdrive.com/dynamicindex17/ajaxcontent.htm I noticed in the demo that sometimes the content takes a long
0
3398
bmallett
by: bmallett | last post by:
First off, i would like to thank everyone for any and all help with this. That being said, I am having a problem retrieving/posting my dynamic form data. I have a form that has multiple options within options. I have everything being dynamically named from the previously dynamically named element. (I hope this makes sense.) I am not able to retrieve any of the dynamically created values. I can view them on the source page but can't pull them...
0
885
by: J. Cliff Dyer | last post by:
On Thu, 2008-05-08 at 10:33 -0500, Victor Subervi wrote: Why are you dynamically creating getpic20.py? Obviously, in the real script, you probably have several of them: getpic1.py, getpic2.py, etc., but is there any reason you couldn't just have one getpic.py, and pass the number in as a parameter in your GET request, like this: http://localhost/getpic.py?id=6&x=1&w=20
0
9673
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9522
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10217
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10167
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10003
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9046
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5440
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5566
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.