Problem with sending a variable(python) while using html

H

Hansan

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
 
J

Jaime Wyant

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
 
H

Hansan

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 :)


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
 
J

Jaime Wyant

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
 
H

Hal Rosser

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 said:
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)
 
K

Kent Johnson

Hansan said:
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
 

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

Forum statistics

Threads
474,237
Messages
2,571,189
Members
47,825
Latest member
XCCMilo924

Latest Threads

Top