Help with variables and html

Discussion in 'HTML' started by Hansan, Apr 27, 2005.

  1. Hansan

    Hansan Guest

    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
     
    Hansan, Apr 27, 2005
    #1
    1. Advertising

  2. "Hansan" <none> wrote:

    > 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.


    If you are using <meta> refresh then something is probably wrong with your
    design.

    > 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'".

    --
    David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
    Home is where the ~/.bashrc is
     
    David Dorward, Apr 27, 2005
    #2
    1. Advertising

  3. Hansan

    Hansan Guest

    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...



    "David Dorward" <> wrote in message
    news:d4oom9$kia$1$...
    > "Hansan" <none> wrote:
    >
    >> 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.

    >
    > If you are using <meta> refresh then something is probably wrong with your
    > design.
    >
    >> 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'".
    >
    > --
    > David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
    > Home is where the ~/.bashrc is
     
    Hansan, Apr 27, 2005
    #3
  4. Hansan

    Mitja Guest

    On Wed, 27 Apr 2005 21:18:00 +0200, David Dorward <>
    wrote:

    > "Hansan" <none> wrote:
    >
    >> 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? :)


    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">);
     
    Mitja, Apr 28, 2005
    #4
  5. Hansan

    Hansan Guest

    Hi all.

    Its working now, thanks for your time

    Take care

    "Mitja" <> wrote in message news:eek:p.spw4vpgedob4us@ibis...
    > On Wed, 27 Apr 2005 21:18:00 +0200, David Dorward <>
    > wrote:
    >
    >> "Hansan" <none> wrote:
    >>
    >>> 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? :)

    >
    > 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">);
     
    Hansan, Apr 28, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    967
  2. Replies:
    10
    Views:
    36,025
    jporter892
    Jun 6, 2011
  3. sagejoshua
    Replies:
    16
    Views:
    676
    Michael Winter
    Nov 9, 2005
  4. Replies:
    9
    Views:
    1,015
  5. Adam Akhtar
    Replies:
    9
    Views:
    598
    Florian Gilcher
    Aug 16, 2008
Loading...

Share This Page