Python in HTML

B

brochu121

Does anyone know of a way to embed python scripts into html, much like
you would javascript or php? I do not want to use this to connect to a
database, but rather for a functional script to be called when a user
clicks on a link to open a page.
 
B

Bruno Desthuilliers

Does anyone know of a way to embed python scripts into html, much like
you would javascript or php?

I think you'd better learn the profound difference between client-side
and server-side scripting.
I do not want to use this to connect to a
database, but rather for a functional script to be called when a user
clicks on a link to open a page.

If it's client-side scripting, javascript is the only option.
 
T

tactics40

Bruno said:
I think you'd better learn the profound difference between client-side
and server-side scripting.

Indeed. You really should Google this before continuing.

Python, like it's (evil?) cousin Perl, can be used as a CGI. If you
don't have one already, go download Apache server to play with on your
own machine and Google "Python CGI" and "Python module cgi".

Basically, (after setting up your server correctly), you can do
"http://localhost/index.py" and your webserver will _execute_ your
script. The server then returns the output of your script (everything
from the print statements) to the web browser.
 
A

Andy Dingley

Python, like it's (evil?) cousin Perl,

Isn't that evil cousin Ruby? Perl's the mad old grandmother in the
attic, spewing out incomprehensible $@^##&% swearing all day.
can be used as a CGI. If you
don't have one already, go download Apache server to play with on your
own machine and Google "Python CGI" and "Python module cgi".

Or if you're cursed with IIS for Windows, then PythonScript does the
job.
 
M

Mitja Trampus

Does anyone know of a way to embed python scripts into html, much like
you would javascript or php?

Two very different things, JS and PHP... First make sure you know what you're after.

If you want PHP-like embedding of code, google for "python server pages". Several
implementations are available:
- an apache handler that comes with mod_python
- a java servlets based one (were not aware of it before, doesn't seem very practical)
- spyce - can act as a simple standalone http server or can be used with
apache/IIS/whatever (by proxying requests)
- probably more
 
M

Mirco Wahab

Thus spoke (e-mail address removed) (on 2006-06-23 17:40):
Does anyone know of a way to embed python scripts into html, much like
you would javascript or php? I do not want to use this to connect to a
database, but rather for a functional script to be called when a user
clicks on a link to open a page.

Aside from the "javascript or php" joke, which
does not belong in such a relation (as others have
already pointed out), there are several methods to
use "PHP"-like Python inclusions, something like:

....
<table>
<%python>
for row range(10):
print "<tr>"
print "<td>NR</td>" + "<td>" + str(row) + "</td>"
print "</tr>"
</%python>
</table>
....


One prominent Example for that would be Myghty
http://www.myghty.org/docs/whatsitdo.myt

some Examples shown here:
http://www.myghty.org/docs/embedding.myt

Regards

Mirco
 
M

Mirco Wahab

Thus spoke Andy Dingley said:
Isn't that evil cousin Ruby? Perl's the mad old grandmother in the
attic, spewing out incomprehensible $@^##&% swearing all day.


There's actually a (real) Anecdote about that:

Larry Wall, BDFL of Perl, working on some Perl4
code, was accompanied by his daughter:

Larry recalls this event later:

"I'm reminded of the day my daughter came in,
looked over my shoulder at some Perl 4 code,
and said, 'What is that, swearing?


Regards

Mirco
 
T

Tim Roberts

Does anyone know of a way to embed python scripts into html, much like
you would javascript or php? I do not want to use this to connect to a
database, but rather for a functional script to be called when a user
clicks on a link to open a page.

If you are running Windows, and you have Python installed, and you have the
Python-Win32 extensions installed, then there is a script you can run which
installs Python as one of the "Windows scripting languages". After that,
you can run Python code in HTML just like Javascript:

<script language="Python">
print "abcde"
</script>

However, it is considered a security risk which is why it is no longer
enabled by default. Plus, it will only work on systems that have it
installed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,678
Members
48,796
Latest member
Greg L.

Latest Threads

Top