Is there any benefit from linking these 3 different ways?

閲覧: 21 回
最初の未読メッセージにスキップ

r

未読、
2017/03/21 13:57:022017/03/21
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

未読、
2017/03/21 14:32:412017/03/21
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. 
全員に返信
投稿者に返信
転送
新着メール 0 件