Need Dynamic Menu Code

Tom tlatoure at systemarts.com
Fri Jan 4 11:15:32 EST 2002


THANK YOU for your detailed reply.  We are using server-side scripting
with Python on IIS.  Would you still recommend the "elaborate CGI for
dynamic menus in python" code you so kindly provided us, or would you
recommend something else?

Thanks again for all your help.


gerson.kurz at t-online.de (Gerson Kurz) wrote in message news:<3c34a524.20734109 at news.t-online.de>...
> On 3 Jan 2002 09:52:12 -0800, tlatoure at systemarts.com (Tom) wrote:
> 
> >How can you create dynamic menus in Python?  Imagine 2 pull-down
> >menus, one for Country, the other for Language.  Your selection of
> >Country establishes the choices/values on the Languages menu
> >(consisting of either native language of selected country or English).
> >
> >We can do this easily in ASP.  But how can we do it in Python?  Advice
> >and input would be greatly appreciated...
> 
> Disclaimer: I'm not much of an ASP fan. 
> 
> ASP is just HTML with special VB Script between <% and %>. So you're
> probably talking about (D)HTML menus and not "GUI" menus. ASP is a
> server-side technique, which allows you to use a language that makes
> perl shine syntaxwise to generate HTML. Whatever the client sees is
> only HTML, therefor you can generate it in any language you like. [You
> could do server-side scripting in Brainfuck if so you desired (see
> http://esoteric.sange.fi/brainfuck/utils/mod_bf-0.2/) and have the
> most annoying proprietary tags be generated by programs that look like
> this: http://esoteric.sange.fi/brainfuck/bf-source/prog/HELLOBF2.BF)
> 
> If you generate a Menu in ASP, you generate HTML tags. The HTML tags
> are just strings. So, if the user chooses one thing, some strings are
> printed, if the user chooses another string, something else gets
> printed. Its not only simple in ASP, its simple in most programming
> languages (but not in Brainfuck). What you need to know is 
> 
> a) The choice the user has made
> b) What HTML tags to display depending upon the choice of the user.
> 
> The thing about webprogramming is that there are so many alternatives
> use. I don't know if you use
> 
> - a python CGI
> - a mod_python script
> - a python script that just generates static HTML for khttpd ;)
> - Client-Side Scripting with Python (IE only)
> - Server-Side Scripting with Python (IIS only)
> - your homegrown webserver based on the SocketServer class
> - a java applet that embedds jython 
> - a java applet that embedds jython which runs a python-powered
> brainfuck interpreter (http://p-nand-q.com/bf/bf-py.txt)
> - a python interpreter written in mod_bf
> etc...
> 
> All mechanisms differ in 
> 
> - how data is transfered from the user (the webbrowser) to the
> application (the webserver / the client in case d)
> - how HTML tags are generated. 
> 
> They do NOT differ in the fact that "a dynamic menu" is just a string
> that gets generated based on user choice. If you can detail which one
> of the methods above you want to use, I can perhaps give you an
> example of generating different HTML tags based on user choice.
> 
> Here is a very elaborate CGI for dynamic menus in python:
> -------------------------------------------------------------
> #!/usr/bin/python -u
> 
> # print "language menu"
> print '''Content-type: text/html
> 
> <html><p>The users choice is either 
> <a href="/cgi-bin/dynamic_menu.py?cmd=english">english</a> or
> <a href="/cgi-bin/dynamic_menu.py?cmd=german">german</a>.</p>
> '''
> 
> import cgi
> form = cgi.FieldStorage()
> 
> # get the users choice
> cmd = None
> if form.has_key('cmd'):
>     cmd = form['cmd'].value
> 
> # display the various "menus"
> if cmd == 'english':
>     print '<p>This is the fancy english menu</p>'
> elif cmd == 'german':
>     print '<p>Das ist das alberne Deutschmenue</p>'
> else:
>     print '<p>The user has not decided on a language yet.</p>'
> --------------------------------------------------------------



More information about the Python-list mailing list