467,081 Members | 1,241 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,081 developers. It's quick & easy.

Executing a python script from an HTML link?

Is this possible? In my CGI app. I display a web page with a link (anchor).
When the link is clicked I want to exectute a python script rather than go
to an HTML page.

Many thanks.
Jul 18 '05 #1
  • viewed: 18699
Share:
7 Replies
Andrew Chalk:
Is this possible? In my CGI app. I display a web page with a link (anchor).
When the link is clicked I want to exectute a python script rather than go
to an HTML page.


IIUYC: make the link tot a Python CGI script instead of to an HTML page.

--
René Pijlman
Jul 18 '05 #2

"Andrew Chalk" <ac****@XXXmagnacartasoftware.com> wrote in message
news:tM*********************@newssvr11.news.prodig y.com...
Is this possible? In my CGI app. I display a web page with a link (anchor). When the link is clicked I want to exectute a python script rather than go
to an HTML page.
Do you want to run the script on the server or the client? If you
want to run it on the client, you can use Python instead of Javascript
(or in addition to Javascript) in the web page. Look at the <script>
tag for the language (I think that's the one - I haven't looked it up
recently) attribute. Otherwise, just invoke Python the same way you would
invoke any other executable, and use the script name as the
first parameter.

John Roth

Many thanks.

Jul 18 '05 #3
Thanks. I want to run the script on the server. The problem is that I don't
have an html page as an HREF. Viz:

<tr><A HREF="Fred.htm">Fred</A>
What replaces Fred.htm to invoke a server-side script?
Regards.
"John Roth" <ne********@jhrothjr.com> wrote in message
news:vn************@news.supernews.com...

"Andrew Chalk" <ac****@XXXmagnacartasoftware.com> wrote in message
news:tM*********************@newssvr11.news.prodig y.com...
Is this possible? In my CGI app. I display a web page with a link

(anchor).
When the link is clicked I want to exectute a python script rather than go to an HTML page.


Do you want to run the script on the server or the client? If you
want to run it on the client, you can use Python instead of Javascript
(or in addition to Javascript) in the web page. Look at the <script>
tag for the language (I think that's the one - I haven't looked it up
recently) attribute. Otherwise, just invoke Python the same way you would
invoke any other executable, and use the script name as the
first parameter.

John Roth

Many thanks.


Jul 18 '05 #4
[Andrew Chalk]
I want to run the script on the server.
Then you will need to figure out how to run the script on the server
;-)

If you're not aware of how to do this, then it's probably best for you
to read up on CGI, which is way of getting web servers to execute
scripts (in any language) when the scripts URL is requested.
The problem is that I don't
have an html page as an HREF. Viz:

<tr><A HREF="Fred.htm">Fred</A>
What replaces Fred.htm to invoke a server-side script?


Whatever is the URL of your script on your server. Examples include

http://www.mydomain.com/cgi-bin/myscript.py
http://www.mydomain.com/cgi-bin/myscript.cgi
http://www.mydomain.com/cgi-bin/mysc...A=v1&paramB=v2

Your python script should then generate (i.e. print out) an HTML page
when it is run (actually it can generate anything, images included,
but HTML is a good place to start). The server takes the output of
your script and sends it to the requesting browser. The browser has no
way of knowing that the HTML did not come from a static file.

You can read about Python and CGI here:-

http://starship.python.net/crew/dave....cgi?req=index

There are other "linkage mechanisms" by which you can cause the
execution of scripts on a server, e.g. mod_python, but none is
conceptually as simple as CGI. Also, CGI tends to be more portable
between different server software, and is almost always supported by
hosting providers.

HTH,

--
alan kennedy
-----------------------------------------------------
check http headers here: http://xhaus.com/headers
email alan: http://xhaus.com/mailto/alan
Jul 18 '05 #5

"Andrew Chalk" <ac****@XXXmagnacartasoftware.com> wrote in message
news:1t*********************@newssvr11.news.prodig y.com...
Thanks. I want to run the script on the server. The problem is that I don't have an html page as an HREF. Viz:

<tr><A HREF="Fred.htm">Fred</A>
What replaces Fred.htm to invoke a server-side script?
Regards.
That's not a Python issue. It's a web server configuration
issue. You should be able to configure your web server
to recognize href="fred.py" as a request to run the fred.py
script using the Python interpreter, and pass back whatever
web page, graphic or other file it outputs. For that matter,
you might even be able to configure it to recognize
"Fred.htm" as a python script, and rewrite the name
to "fred.py."

John Roth

"John Roth" <ne********@jhrothjr.com> wrote in message
news:vn************@news.supernews.com...

"Andrew Chalk" <ac****@XXXmagnacartasoftware.com> wrote in message
news:tM*********************@newssvr11.news.prodig y.com...
Is this possible? In my CGI app. I display a web page with a link (anchor).
When the link is clicked I want to exectute a python script rather
than go to an HTML page.


Do you want to run the script on the server or the client? If you
want to run it on the client, you can use Python instead of Javascript
(or in addition to Javascript) in the web page. Look at the <script>
tag for the language (I think that's the one - I haven't looked it up
recently) attribute. Otherwise, just invoke Python the same way you would invoke any other executable, and use the script name as the
first parameter.

John Roth

Many thanks.



Jul 18 '05 #6
Thanks!
"Rene Pijlman" <re********************@my.address.is.invalid> wrote in
message news:1c********************************@4ax.com...
Andrew Chalk:
Is this possible? In my CGI app. I display a web page with a link (anchor).When the link is clicked I want to exectute a python script rather than goto an HTML page.


IIUYC: make the link tot a Python CGI script instead of to an HTML page.

--
René Pijlman

Jul 18 '05 #7
Thanks!
"Alan Kennedy" <al****@hotmail.com> wrote in message
news:3F***************@hotmail.com...
[Andrew Chalk]
I want to run the script on the server.


Then you will need to figure out how to run the script on the server
;-)

If you're not aware of how to do this, then it's probably best for you
to read up on CGI, which is way of getting web servers to execute
scripts (in any language) when the scripts URL is requested.
The problem is that I don't
have an html page as an HREF. Viz:

<tr><A HREF="Fred.htm">Fred</A>
What replaces Fred.htm to invoke a server-side script?


Whatever is the URL of your script on your server. Examples include

http://www.mydomain.com/cgi-bin/myscript.py
http://www.mydomain.com/cgi-bin/myscript.cgi
http://www.mydomain.com/cgi-bin/mysc...A=v1&paramB=v2

Your python script should then generate (i.e. print out) an HTML page
when it is run (actually it can generate anything, images included,
but HTML is a good place to start). The server takes the output of
your script and sends it to the requesting browser. The browser has no
way of knowing that the HTML did not come from a static file.

You can read about Python and CGI here:-

http://starship.python.net/crew/dave....cgi?req=index

There are other "linkage mechanisms" by which you can cause the
execution of scripts on a server, e.g. mod_python, but none is
conceptually as simple as CGI. Also, CGI tends to be more portable
between different server software, and is almost always supported by
hosting providers.

HTH,

--
alan kennedy
-----------------------------------------------------
check http headers here: http://xhaus.com/headers
email alan: http://xhaus.com/mailto/alan

Jul 18 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by sarmin kho | last post: by
6 posts views Thread by Dfenestr8 | last post: by
3 posts views Thread by olaufr@gmail.com | last post: by
reply views Thread by phoolimin@gmail.com | last post: by
2 posts views Thread by Jorgen Bodde | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.