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 14 5412
asdf wrote:
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
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.
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.
There's also more advanced ways you can make python code run in a
web-service. Cherrypy comes to mind, as well as the myriad python MVC
frameworks.
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
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.
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.
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.
asdf wrote:
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
Take a look at Django. It may be overkill for this first project but any time
you spend learning it should be paid back in future projects.
-Larry
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.
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.
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 indefinitel y. 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).
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.
>
>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.
Aidan wrote:
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).
To be clear, you can set the content attribute value to any arbitrary
integer value.
>
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.
>>
>>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. >
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.
On Wed, 11 Jun 2008 01:05:45 +0000, 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
Here's a simplified Django and AJAX solution:
1. Install Django http://www.djangoproject.com/documentation/install/
and choose the place to strore your Django apps
2. Run 'python django-admin.py startproject YOURPROJECTNAME '
3. Create views.py file inside YOURPROJECTNAME directory
with something like this:
from datetime import datetime
from django.http import HttpResponse
# import your script here
def myscript(reques t):
output = """\
<html>
<body>
<script type="text/javascript">
function ajaxFunction()
{
var xmlHttp;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest( );
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject(" Msxml2.XMLHTTP" );
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject(" Microsoft.XMLHT TP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
xmlHttp.onready statechange=fun ction()
{
if(xmlHttp.read yState==4)
{
document.getEle mentById("hello ").innerHTML=xm lHttp.responseT ext;
setTimeout('aja xFunction();', 1000);
}
}
xmlHttp.open("G ET", "../ajax/", true);
xmlHttp.send(nu ll);
}
window.onload = ajaxFunction;
</script>
<div id="hello"></div>
</body>
</html>"""
return HttpResponse(ou tput)
def ajax(request):
output = """
<p>Hello World from Django and AJAX</p>
<p>Current time is: %s</p>
""" % str(datetime.no w())[11:19]
return HttpResponse(ou tput, mimetype="text/plain")
Note, that refresh time is in 'setTimeout('aj axFunction();', 1000);' in
this example it is 1 second.
3. edit urls.py inside YOURPROJECTNAME directory to something like this:
from django.conf.url s.defaults import *
urlpatterns = patterns('',
(r'^myscript/$', 'YOURPROJECTNAM E.views.myscrip t'),
(r'^ajax/$', 'YOURPROJECTNAM E.views.ajax'),
)
4. run 'python manage.py runserver' inside YOURPROJECTNAME directory
5. point your browser to 'http://127.0.0.1:8000/myscript/' and you'll see
the result.
6. Deploy your app to Apache web server http://www.djangoproject.com/documentation/modpython/ http://www.djangoproject.com/documentation/fastcgi/
Hope this Django/AJAX introduction is helpfull
Please note that this code is extremely simplified you probably need to
learn more about Django and AJAX/Javascript by yourself
Ivan This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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...
|
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
|
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:
|
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...
| |
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...
|
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
|
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...
|
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
|
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...
|
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,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |