By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,719 Members | 1,195 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,719 IT Pros & Developers. It's quick & easy.

Problem with sending a variable(python) while using html

P: n/a
Hi all.

I am working on a webpage where I use python and html.

When I want to send one variable to a new script/page I use the following
code:
0) print '''<input type=hidden name="eventid"
value='''+str(variable_name)+'''>'''

This works fine, the problem occurs when I want to send a variable to a page
while using a 1)meta refresh or a 2)Href.
1) and 2) works fine as they are but not when I try to send the variable
with them.

The working version of 1) and 2) could look like
1) print ''<META HTTP-EQUIV="Refresh" CONTENT="0;URL=page xxx">'''
2) print "<a href='page xxx?id=", variable, "'>", "some text", "</a>"

What I have to do is to combine 0) with 1) so that I can send the variable
while using a meta refresh
and 0) and 2)

But I no matter how hard I try I cant get it done.

Can any of you experienced users give me some guidance.

I would really appreciate it.

Thanks
Jul 19 '05 #1
Share this Question
Share on Google+
6 Replies

P: n/a
On 4/27/05, Hansan <no**@bag.python.org> wrote:
Hi all.

I am working on a webpage where I use python and html.

When I want to send one variable to a new script/page I use the following
code:
0) print '''<input type=hidden name="eventid"
value='''+str(variable_name)+'''>'''

This works fine, the problem occurs when I want to send a variable to a page
while using a 1)meta refresh or a 2)Href.
1) and 2) works fine as they are but not when I try to send the variable
with them.

The working version of 1) and 2) could look like
1) print ''<META HTTP-EQUIV="Refresh" CONTENT="0;URL=page xxx">'''
2) print "<a href='page xxx?id=", variable, "'>", "some text", "</a>"


What exactly does the "non-working" version look like? Perhaps a
snippet of broken code would be helpful here?

jw
Jul 19 '05 #2

P: n/a
Hi.

Sorry forgot to post a "non-working" example

That could be
print "<a href=script.py?id=", variable, "'>", "some text" <input
type=hidden name="eventid" value='''+str(variable_name)+'''>'''</a>"

I know that it isnt very creative, but I am having a hard time getting html
to work together with python.

When the link "some text" is clicked I want to send both the first variable
called variable and the second one(variable_name) to the script (script.py)

Hope that makes some sense :)
"Jaime Wyant" <pr***********@gmail.com> wrote in message
news:ma**************************************@pyth on.org...
On 4/27/05, Hansan <no**@bag.python.org> wrote:
Hi all.

I am working on a webpage where I use python and html.

When I want to send one variable to a new script/page I use the following
code:
0) print '''<input type=hidden name="eventid"
value='''+str(variable_name)+'''>'''

This works fine, the problem occurs when I want to send a variable to a
page
while using a 1)meta refresh or a 2)Href.
1) and 2) works fine as they are but not when I try to send the variable
with them.

The working version of 1) and 2) could look like
1) print ''<META HTTP-EQUIV="Refresh" CONTENT="0;URL=page xxx">'''
2) print "<a href='page xxx?id=", variable, "'>", "some text", "</a>"


What exactly does the "non-working" version look like? Perhaps a
snippet of broken code would be helpful here?

jw
Jul 19 '05 #3

P: n/a
On 4/27/05, Hansan <no**@bag.python.org> wrote:
Hi.

Sorry forgot to post a "non-working" example

That could be
print "<a href=script.py?id=", variable, "'>", "some text" <input
type=hidden name="eventid" value='''+str(variable_name)+'''>'''</a>"

I know that it isnt very creative, but I am having a hard time getting html
to work together with python.

When the link "some text" is clicked I want to send both the first variable
called variable and the second one(variable_name) to the script (script.py)

Hope that makes some sense :)


Got it - I think :)

# Create a link that passes the value of `variable' to script.py via
# the id parameter. You may want to escape `variable' somehow
# in case it contains spaces or something else that isn't valid.
print '<a href=script.py?id="%s"> some text </a>' % variable

# Create a hidden input variable named `eventid' that contains a value of
# `variable_name'
print '<input type=hidden name="eventid" value="%s">' % variable_name

hth,
jw
Jul 19 '05 #4

P: n/a
append "&eventid=str(variable_name)" to the url in the link
The hidden field is not sent unless the form is submitted.
If you use the link - you send the data appended to the url

"Hansan" <none> wrote in message
news:42***********************@nntp03.dk.telia.net ...
Hi.

Sorry forgot to post a "non-working" example

That could be
print "<a href=script.py?id=", variable, "'>", "some text" <input
type=hidden name="eventid" value='''+str(variable_name)+'''>'''</a>"

I know that it isnt very creative, but I am having a hard time getting html to work together with python.

When the link "some text" is clicked I want to send both the first variable called variable and the second one(variable_name) to the script

(script.py)
Jul 19 '05 #5

P: n/a
Hansan wrote:
Hi.

Sorry forgot to post a "non-working" example

That could be
print "<a href=script.py?id=", variable, "'>", "some text" <input
type=hidden name="eventid" value='''+str(variable_name)+'''>'''</a>"

I know that it isnt very creative, but I am having a hard time getting html
to work together with python.

When the link "some text" is clicked I want to send both the first variable
called variable and the second one(variable_name) to the script (script.py)


As Hal pointed out you need to put both variables into the link. Also, you should be url-encoding
your values using urllib.quote_plus(); otherwise variable values containing characters like &= will
cause trouble. So for the link I would use

from ulrlib import quote_plus
link = "<a href='script.py?id=%s&eventid=%s'>" % (quote_plus(str(variable)),
quote_plus(str(variable_name)))

Then you may need urllib.unquote_plus() on the reading end depending on the server.

Kent
Jul 19 '05 #6

P: n/a
Thanks for you help, it is working now :D

Take care
"Kent Johnson" <ke****@tds.net> wrote in message
news:42**********@newspeer2.tds.net...
Hansan wrote:
Hi.

Sorry forgot to post a "non-working" example

That could be
print "<a href=script.py?id=", variable, "'>", "some text" <input
type=hidden name="eventid" value='''+str(variable_name)+'''>'''</a>"

I know that it isnt very creative, but I am having a hard time getting
html to work together with python.

When the link "some text" is clicked I want to send both the first
variable called variable and the second one(variable_name) to the script
(script.py)


As Hal pointed out you need to put both variables into the link. Also, you
should be url-encoding your values using urllib.quote_plus(); otherwise
variable values containing characters like &= will cause trouble. So for
the link I would use

from ulrlib import quote_plus
link = "<a href='script.py?id=%s&eventid=%s'>" %
(quote_plus(str(variable)), quote_plus(str(variable_name)))

Then you may need urllib.unquote_plus() on the reading end depending on
the server.

Kent

Jul 19 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.