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. 

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. 

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>

And all the above are in the same function 'test', so can i omit 'test' in 
the URL?

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