473,503 Members | 1,648 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with sending a variable(python) while using html

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
6 6727
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
9233
by: Christian Eriksson | last post by:
Hi! I have a problem using the environment variable LD_LIBRARY_PATH in my perl script. Everything works fine when I set it at the command prompt and then runs my perl script like this: ...
0
445
by: d | last post by:
Hey all, I've been having a weird problem using com objects in IIS 4. I've built a middleware system that can be called with XML requests over HTTP. The request is sent to an ASP page which...
2
9196
by: Kent Lewandowski | last post by:
hi all, Recently I wrote some stored procedures using java jdbc code (admittedly my first stab) and then tried to implement the same within java packages (for code reuse). I encountered...
4
1589
by: Justin | last post by:
I have a fairly large piece of html, about 50 lines that I would like to send via an ASP.NET page I was wondering what would be the best and cleanest way to do this? Is there a way I can put the...
10
2226
by: Blaxer | last post by:
There is probably a really easy way to do this, so please forgive me but I would like to set the value of a variable from a variable, an example would be... function Calculate_Something(ByVal...
1
2091
by: sck10 | last post by:
Hello, I am pulling data from a SQL Server table. One field that is (varchar 4000) is used to show notes. I am using a FormView for showing and editing the data. When the form is in Item...
18
2025
by: **Developer** | last post by:
If e.Button = MouseButtons.Left Then also from a Dim Answer As DialogResult = MessageBox.Show.. Select Case Answer Case DialogResult.Yes
7
4375
by: Ray Booysen | last post by:
Hi all I'm sending email via ASP.NET in HTML mode. Each email has exactly one attachment and I do have full access to the SMTP server. However, if I send the email in HTML format, the...
1
3150
by: ttcplkavi | last post by:
hello.. Is anybody know how to do Auto mail sending using postgresql .. Please reply asap
5
7790
by: cappieins | last post by:
Hi, i've got a problem using PHP FPDF library to create PDF files send inline to a browser window. The created PDF file opens correctly in the browser (IE 6), but if I want to save it to my...
0
7198
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7271
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
7319
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...
1
6979
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
5570
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4998
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3149
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1498
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.