Help with variables and 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 html users give me some guidance.

I would really appreciate it.

Thanks
 
D

David Dorward

Hansan said:
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)+'''>'''

Isn't Python supposed to be really elegant? :)
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>"

So you want to construct a URL with a query string where the values for each
parameter are determined pragmatically in your Python script?

The syntax is as per a normal request (http://www.example.com/myscript) with
a "?" appended followed by any number of key=value pairs separated by
semi-colons or ampersands (semi-colons are probably a better choice since
you do not have to represent them with character references in HTML).

Each key and value needs to be URL Encoded, Python probably includes a
method for that in its CGI library.

Oh, and spaces must be URL encoded too, so "href='page xxx'" is not a URL.
You need to represent that as "href='page%20xxx'".
 
H

Hansan

Hi

Btw the "<a href='page xxx was just an example in my code I have my
script.py file in there, and heh I don't know if python should be that
elegant, but it normally gets the job done :)

Not sure I quite get it yet, but I will get some sleep and try it again..

Thanks for your response...
 
M

Mitja

Isn't Python supposed to be really elegant? :)

print '<input type="hidden" name="eventid" value="%d">' % variable_name
or
print '<input type="hidden" name="eventid" value="'+`variable_name`+'">'

I prefer python over perl, but in this simple case, perl _is_ more elegant
with its
print qq(<input type="hidden" name="eventid" value="$variable_name">);
 

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

Similar Threads


Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top