Whew! Thank you, Ricardo! That did the trick. It's even beginning to make sense to me.
/dps On Monday, August 26, 2013 7:13:04 PM UTC-7, Ricardo Cárdenas wrote: > > Hello Dave, > > You're almost there actually. You are correct that last() gives you a row > object instead of a rows object. Then, as_dict() uses the row object to > make a Python dict > object<http://docs.python.org/2/library/stdtypes.html#mapping-types-dict>, > an object which maps keys (the field names) to values (the field values). > > In your view, your for loop iterates over the keys, but prints the keys > instead of the values. If you change the LI line to > > {{=LI(logs[log])}} > > you'll see the field values you are expecting. Or display both the field > names and the field values with > > {{=LI(log, ": ", logs[log])}} > > -Ricardo > > > On Monday, August 26, 2013 7:56:13 PM UTC-5, Dave S wrote: >> >> After reading >> http://www.web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#first-and-last, >> >> I was trying to use >> >> def my_ctlr: >> results = db().select(db.logtable.ALL, orderby=db.logtable.field1) >> logs = results.last().as_dict() >> return dict(logs = logs) >> >> >> >> with a view using this >> {{extend 'layout.html'}} >> <h1>Hi</h1> >> >> >> <ul> >> {{for log in logs:}} >> {{=LI(log)}} >> {{pass}} >> </ul> >> >> >> and was expecting to get a row object (if I remove the .last(), I get a >> bunch of row objects). Instead, I get several li items displayed that >> apparently strings, and happen to match the field names. Since they are >> strings, I can't apply .values() or .items(). >> >> If I replace the loop with >> {{=BEAUTIFY(response._vars)}} >> >> (as in generic.html) >> I get the fieldnames and their values displayed in the >> programmer-friendly format of the BEAUTIFY operator. >> >> It is obvious that I don't know what I'm doing, especially in regards to >> the last() operator. How can I get to having the values display as the LI >> contents? >> >> Version is 2.5.1-stable+timestamp.2013.06.06.15.39.19 >> (Running on Rocket 1.2.6) >> >> Thanks. >> >> /dps >> >> -- --- 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.

