How to force a SQLTABLE link to link to external pages?

New to Web2py, so my question may not be too clear. I am trying to make a shipment tracking page and I have a simple database with a tracking number and a shipper ID. Following the examples, my application can display and add new entries in db shipment. Now I want to add links to the displayed entries that will take you to the carrier tracking page for this tracking number. The tracking page URL will be generated from the default string for each sender to which the tracking number will be added. How can I make the results in links to the corresponding tracking page?

+3
source share
3 answers

If you display a record through SQLFORM, Crud, SQLTABLE or SQLFORM.grid, you can set the submit attribute in the tracking number field to display the link:

db.define_table('shipper',
    Field('name'),
    Field('url'),
    format='%(name)s')

db.define_table('shipment',
    Field('tracking_number', represent=lambda value, row: A(value,
        _href=row.shipper.url + value)),
    Field('shipper', db.shipper))

It is assumed that you store the sender URLs in a separate table.

+2
source

I changed it to this and it almost works:

db.define_table('carrier',
    Field('name',),
    Field('url',),
    format='%(name)s')

db.define_table('shipment',
    Field('shipment_id', represent=lambda value,row: \
        A(value, _href=(row.carrier.url + value, ))),
    Field('carrier', db.carrier))

shipment_id is a link, but it points to "http://127.0.0.1:8000/tracker/default/www.bing.com/search?q=trumpet", where "www.bing.com/search? q = ' and 'trumpet' are carrier.url and shipment.shipment_id values โ€‹โ€‹respectively (for testing only). How can I leave "http://127.0.0.1:8000/tracker/default/"?

+1
source

, :

db.define_table('carrier',
    Field('name',),
    Field('url',),
    format='%(name)s')

db.define_table('shipment',
    Field('shipment_id', represent=lambda value,row: \
        A(value, _href=row.carrier.url + value)),
    Field('carrier', db.carrier))

. href. , , , . -, URL- "http://". .

0

All Articles