Is there any benefit from linking these 3 different ways?

21 views
Skip to first unread message

r

unread,
Mar 21, 2017, 1:57:02 PM3/21/17
to web2py-users

                    <a href="./lookup?item={{=db.id}}">

result: /lookup?item=1

 

                    <a href={{=URL('lookup',args=db.id)}}>

result: /lookup/1

 

                    <a href="{{=URL('lookup', vars={'item':db.id})}}">

result: /lookup?item=1


Just wondering, is there any benefit from using one method over the others? I plan on retrieving the URL args/vars on the webpage. For me the 1st one seems like the simplest but no difference vs the 3rd. So why would people use the 3rd over the 1st when linking? 

Massimo Di Pierro

unread,
Mar 21, 2017, 2:32:41 PM3/21/17
to web2py-users
This is wrong:

<a href="./lookup?item={{=db.id}}">

The reason is that it would break if the path_info.count('/')!=2 in the current page.

These two produce the same net effect:

<a href={{=URL('lookup', args=db.id)}}>
<a href="{{=URL('lookup', vars={'item':db.id})}}">

I would use args if 'lookup' GETs a persistent object that resides inDB and I would use vars if it GETs the result of a computation and you are passing imput parameters. Anyway, this is purely for aesthetic reasons. 
Reply all
Reply to author
Forward
0 new messages