You can think of request.args as a Python list.  You can find out more 
about Python lists here 
http://docs.python.org/2/tutorial/introduction.html#lists and here 
http://docs.python.org/2/tutorial/datastructures.html#more-on-lists

You can think of request.vars as a Python dictionary.  Look here: 
http://docs.python.org/2/tutorial/datastructures.html#dictionaries

The Web2py manual also has an introductory chapter on Python 
http://web2py.com/books/default/chapter/29/02

On Tuesday, April 2, 2013 6:20:21 AM UTC-4, Niphlod wrote:
>
>
>
> On Tuesday, April 2, 2013 10:57:57 AM UTC+2, [email protected] wrote:
>>
>> Thank you for your reply again :)
>> Okay, i just did a google search on the term "foobar", and haha i have 
>> been wondering why does it appear anywhere! 
>> anyway, hmm, it seems clearer with your examples. so if i were to use 
>> args, like you said, to turn on bulb 1, i will put it as something like:
>>
>> <a href = "{{=URL('test', args =['bulb', '1', 'on'])}}"><img src 
>> ="/Comfort2/static/images/on.jpg" width ="75" height="75"></a> ?
>>
>> in default.py, i put this?
>>
>>  if request.args(0)=='1':
>>         serialport.write("\x03O!0101\x0D") # serial command to turn the 
>> light on. 
>>
>>
> [bulb, 1, on] "translates" to 
> request.args(0) = bulb
> request.args(1) = 1
> etc etc etc (i.e. numbering starts from 0)
>  
>
>> and if using vars:
>>
>> <a href = "{{=URL('test',  vars = dict(bulb='1', state='on' ))}}"><img 
>> src ="/Comfort2/static/images/on.jpg" width ="75" height="75"></a> ?
>>
>> if request.vars ={'bulb':1, 'state' :on}
>>         serialport.write("\x03O!0101\x0D") # serial command to turn the 
>> light on. 
>>
>
> better to be a little less specific
> if request.vars.bulb == '1' and request.vars.state == 'on':
>  
>
>>
>> what about the following URL? what will it do?
>>
>> <a href = "{{=URL('test', args =['bulb', '1'], vars = 
>> dict(state='on'))}}"><img src ="/Comfort2/static/images/on.jpg" width ="75" 
>> height="75"></a>
>>
>>
> request.args(0) = bulb
> request.args(1) = 1
> request.vars.state = 'on'
>
> all of this can be discovered if you turn the response.generic_patterns on 
> and you do (for testing purposes) a simple
> def test():
>     return dict()
>
> In the generic view there's included "response toolbar" that you can use 
> to "inspect" what's going on (e.g., what request.args is specifically)
> Or, if you have a view already, include at the top
> {{=response.toolbar()}} 
> to show it.
>  
>
>> And all the above are in the same function 'test', so can i omit 'test' 
>> in the URL?
>>
>
> See the book on how to use the URL() function. 
> http://web2py.com/books/default/chapter/29/04#URL
>
> URL() without arguments "points" to the app/controller/function that 
> generated it.
>  
>
>>
>> thanks again!
>>
>> On Tuesday, April 2, 2013 4:28:50 PM UTC+8, Niphlod wrote:
>>>
>>> /app/default/test
>>> points to executing your test() inside the controller named default.py
>>> args and vars are, in respect
>>> - args : /app/default/test/*1/2/3* 
>>> - vars : /app/default/test?*foo=bar&foo=bar2&hello=world*
>>>
>>> To sum up, args are fine if you want cleaner urls, but you can't put 
>>> whatever you want on them (imagine something like /app/default/test/*
>>> รนร +:\*/
>>> , not a "smart" way to pass garbles on the url, but, e.g., something 
>>> like /app/default/test/*1/on* where *1 *is the "bulb" number and *on*is the 
>>> "action" you want to do seems fine).
>>> "Vars" on the other hand allow more flexibility, "garbled" parameters 
>>> are allowed...maybe the nicest "feature" is that if you need a single 
>>> variable holding multiple values "vars" parses them automatically (e.g. 
>>> "turn on bulb 1 and bulb 2" can be done with /app/default/test?*
>>> bulb=1&bulb=2&action=on*) . Urls are not "clean" as with "args" but the 
>>> functionality is the same.
>>>
>>> Bottomline, use what you feel appropriate, either one would do just 
>>> fine. 
>>>
>>> On Tuesday, April 2, 2013 9:56:25 AM UTC+2, [email protected] wrote:
>>>>
>>>> Hi guys! Sorry but I still do not quite understand after reading the 
>>>> chapters about "Dispatching" and "URL". i guess my programming foundation 
>>>> isn't that strong... and i have problem understanding without referring to 
>>>> examples.
>>>>
>>>> Here is my situation and i would like to get a general idea on how to 
>>>> solve the problem. May be my idea was wrong so please correct me :)
>>>>
>>>> I have just successfully connect a device to my Raspberry Pi, with 
>>>> web2py as the webserver on Raspberry pi. Currently, i have created a home 
>>>> page using the template, and there is a "Login" button on it. When i click 
>>>> on the image (button), it directs me to default/test.html. the device gets 
>>>> the login information and turns on and off the testlight. 
>>>>
>>>> in default/index.html:
>>>>
>>>> <a href = "{{=URL 
>>>> <https://10.0.0.132/examples/global/vars/URL>(c='default', 
>>>> f='test')}}"><img src ="/Comfort2/static/images/login.jpg" width ="128" 
>>>> height="69"></a>
>>>>
>>>>
>>>> in default.py:
>>>>
>>>> def test():
>>>>     import serial
>>>>     import time
>>>>     response <https://10.0.0.132/examples/global/vars/response>.flash=T 
>>>> <https://10.0.0.132/examples/global/vars/T>("welcome home!")
>>>>     time.sleep(1)
>>>>
>>>>     serialport= serial.Serial("/dev/ttyAMA0", 9600, timeout=0.5) #opening 
>>>> the port
>>>>     
>>>>
>>>>     serialport.write("\x03LI1234\x0D") #write a serial command to log into 
>>>> the device
>>>>     reply=serialport.readlines(1)
>>>>     print reply
>>>>     time.sleep(1)
>>>>     serialport.write("\x03O!0101\x0D") #turn on a testlight
>>>>     time.sleep(2)
>>>>     serialport.write("\x03O!0100\x0D") #turn off a testlight
>>>>     return dict()
>>>>
>>>>  
>>>> However, i would like to separate it into a few tasks. So, after 
>>>> pressing the "login" button, it will only login and direct me to test.html 
>>>> with 2 buttons (Turn on light and turn off light). if i press on the turn 
>>>> on light button, the testlight will turn on and same for the other one. I 
>>>> would like all these to be under one function because the commands can 
>>>> only 
>>>> be sent when it is logged into the device. (if it is under another 
>>>> function, i will need to login again.) So do i need to use args and vars 
>>>> at 
>>>> this point? 
>>>>
>>>> I do not really understand what is args and vars and how are they used. 
>>>> the information in the chapters taught me that 
>>>> request.args = ['x', 'y', 'z']  
>>>> request.vars={'p':1, 'q':2} 
>>>>
>>>> but what are x,y,z,p, q, 1 and 2? under what conditions are they 
>>>> declared and where do they appear?
>>>>
>>>> Another question: can i display a jQuery keypad using web2py? 
>>>>
>>>> My progress using cherrypy is slightly more ahead than web2py. i am 
>>>> sure i can transfer my work in cherrypy over to web2py... but i must get 
>>>> the whole concept clear... please help me. 
>>>> sorry that i sound very noob.... but much thanks to everyone for your 
>>>> patience and guidance! :)
>>>>
>>>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to