Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #15019 > unrolled thread

Re: passing Python data to a javascript function

Started byChris Rebert <clp2@rebertia.com>
First post2011-10-26 19:42 -0700
Last post2011-10-26 19:42 -0700
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: passing Python data to a javascript function Chris Rebert <clp2@rebertia.com> - 2011-10-26 19:42 -0700

#15019 — Re: passing Python data to a javascript function

FromChris Rebert <clp2@rebertia.com>
Date2011-10-26 19:42 -0700
SubjectRe: passing Python data to a javascript function
Message-ID<mailman.2244.1319683332.27778.python-list@python.org>
On Wed, Oct 26, 2011 at 7:25 PM, Bill Allen <wallenpb@gmail.com> wrote:
>
> Benjamin,
>
> I was afraid I was doing that.   I have simplified it quite a bit, still not
> getting the output I am looking for.   I am down to that I am not passing
> the value in the onload=showPID() call correctly.  I know this is getting a
> bit far from a Python issue now, but if you have more insight on this, I
> would appreciate it.  Is there another way of passing the data from the
> Python script to the javascript than what I am doing in this CGI?

The problem is that you're not passing the data at all. You never
interpolate the pid_data value into the string(s) constituting your
embedded JavaScript (though you did do it just fine in the pure HTML).
The Python variable `pid_data` is not somehow magically accessible to
JavaScript; you must explicitly insert its value somewhere.

<snip>
> pid_data = str(os.getpid())
<snip>
> print """
<snip>
> <body onload="showPID(pid_data)">

Change that line to:
<body onload="showPID("""+pid_data+""")">

As an example, if the PID happens to be 42, then the outputted
fragment will end up being:
<body onload="showPID(42)">

As a sidenote, I would recommend using something higher-level than the
`cgi` module. Python has an abundance of web frameworks and templating
languages; take your pick.

Cheers,
Chris
--
http://rebertia.com

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web