473,399 Members | 3,603 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Python in HTML

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.

Jun 23 '06 #1
7 1558
br*******@gmail.com wrote:
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.

--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom.gro'.split('@')])"
Jun 23 '06 #2
Bruno Desthuilliers wrote:
br*******@gmail.com wrote:
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.


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.

Jun 23 '06 #3
ta*******@gmail.com wrote:
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.

Jun 23 '06 #4
br*******@gmail.com wrote:
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
Jun 23 '06 #5
Thus spoke br*******@gmail.com (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
Jun 25 '06 #6
Thus spoke Andy Dingley <di*****@codesmiths.com> (on 2006-06-23 18:10):
ta*******@gmail.com wrote:
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.

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
Jun 25 '06 #7
br*******@gmail.com wrote:

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.
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Jun 26 '06 #8

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

Similar topics

0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
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,...
0
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...
0
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...
0
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...

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.