FAQ
I'm having a hard time understanding this, can someone explain?

Running a CGI with query string:

?action=Find&page=Data

Script includes these lines:

form=cgi.FieldStorage(keep_blank_values=1)
print("Content-type:text/html\n\n")
print(cgi.print_form(form))

Output:

Form Contents:

action: <class 'cgi.MiniFieldStorage'>
MiniFieldStorage('action', 'Find')
page: <class 'cgi.MiniFieldStorage'>
MiniFieldStorage('page', 'Data')


It looks like every variable in the query string instantiates a
MiniFieldStorage with that value, is that the case? And if so, what
sort of cool tricks could I do with that feature? Because so far I am
doing CGI and it is a big old mess. Intercepting every variable is
complicated and confusing. Is there an easier way?

-- Gnarlie

Search Discussions

  • Tim Roberts at Nov 22, 2010 at 4:25 am

    Gnarlodious wrote:
    I'm having a hard time understanding this, can someone explain?

    Running a CGI with query string:

    ?action=Find&page=Data

    Script includes these lines:

    form=cgi.FieldStorage(keep_blank_values=1)
    print("Content-type:text/html\n\n")
    print(cgi.print_form(form))

    Output:

    Form Contents:

    action: <class 'cgi.MiniFieldStorage'>
    MiniFieldStorage('action', 'Find')
    page: <class 'cgi.MiniFieldStorage'>
    MiniFieldStorage('page', 'Data')

    It looks like every variable in the query string instantiates a
    MiniFieldStorage with that value, is that the case?
    Yes, unless it's a "file" type, then it is a full FieldStorage.
    And if so, what
    sort of cool tricks could I do with that feature? Because so far I am
    doing CGI and it is a big old mess. Intercepting every variable is
    complicated and confusing. Is there an easier way?
    Have you looked at the source code? That's the beauty of Python. It's all
    exposed for you. MiniFieldStorage has a .name attribute and a .value
    attribute. So, for example:

    print form['action'].value
    print form['page'].value

    If you're not sure whether the value will be specified:

    if 'action' in form:
    action = form['action'].value
    --
    Tim Roberts, timr at probo.com
    Providenza & Boekelheide, Inc.
  • Gnarlodious at Nov 23, 2010 at 4:40 am
    Let me rephrase the question. Say I have a query string like this:

    ?viewÚta&item˜75

    What I want to do is simply invoke process "view" with variable
    "Data". This would replace my existing query string mess which looks
    like this:

    if 'view' in form and 'item' in form:
    HTML=view(Data, item(9875))

    so it just seems like it would be easier to encode the process in the
    query rather than filtering the query string.

    -- Gnarlie
  • Gnarlodious at Nov 24, 2010 at 2:01 am

    On Nov 22, 11:32?pm, Dennis Lee Bieber wrote:

    ? ? ? ? Or upgrade to some modernistic framework wherein the application is
    a monolithic program and the "name/" portion maps to methods/functions
    within the application...
    Yes, that describes what I am looking for! Is there such a modernistic
    framework? Links?

    -- Gnarlie, K5ZN
  • Ian Kelly at Nov 24, 2010 at 2:22 am

    On 11/23/2010 7:01 PM, Gnarlodious wrote:
    On Nov 22, 11:32 pm, Dennis Lee Bieber wrote:

    Or upgrade to some modernistic framework wherein the application is
    a monolithic program and the "name/" portion maps to methods/functions
    within the application...
    Yes, that describes what I am looking for! Is there such a modernistic
    framework? Links?
    Try Django[1] or TurboGears[2].

    [1] http://www.djangoproject.com/
    [2] http://www.turbogears.org/

    Cheers,
    Ian
  • Gnarlodious at Nov 24, 2010 at 2:27 pm

    On Nov 23, 7:22?pm, Ian Kelly wrote:

    Try Django[1] or TurboGears[2].

    [1]http://www.djangoproject.com/
    [2]http://www.turbogears.org/
    Thanks, never understood what those programs were for.

    -- Gnarlie

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedNov 21, '10 at 1:19a
activeNov 24, '10 at 2:27p
posts6
users3
websitepython.org

People

Translate

site design / logo © 2022 Grokbase