You're not using the iteration variable.

This line:
{{=LI(shares.asx_code)}}

should be:
{{=LI(asx_code.asx_code)}}

But a more logical iteration variable would be 'share':

{{extend 'layout.html'}}
<h1>Share portfolio</h1>
<ul>
{{for share in shares:}}
{{=LI(share.asx_code)}}
{{pass}}
</ul>



On Sun, May 2, 2010 at 11:02 AM, ztd <[email protected]> wrote:

> Hi,
>
> here is an error I receive in a simple stock tracking application I'm
> making to help me learn Web2Py:
>
> Traceback (most recent call last):
>  File "gluon/restricted.py", line 178, in restricted
>  File "C:\Users\Zac\Desktop\web2py\applications\shares/views\default/
> index.html", line 86, in <module>
> AttributeError: 'Rows' object has no attribute 'asx_code'
>
> I think the problem is to do with passing variables between the
> controller and view. I've based this app on the 'image blog' example
> in the book. Here is my code so far:
>
> ---db.py---
>
> db.define_table('shares',
>    Field('asx_code'),
>    Field('date_added','datetime',default=request.now),
>    Field('quantity'),
>    Field('buy_price'))
>
> db.define_table('prices',
>    Field('share_id',db.shares),
>    Field('date','datetime',default=request.now),
>    Field('price_low',default='0'),
>    Field('price_high',default='0'),
>    Field('price_close',default='0'))
>
> db.shares.asx_code.requires =
> [IS_NOT_EMPTY(),IS_NOT_IN_DB(db,db.shares.asx_code)]
> db.shares.quantity.requires = IS_NOT_EMPTY()
> db.shares.buy_price.requires = IS_NOT_EMPTY()
>
> db.prices.share_id.requires = IS_IN_DB(db,db.shares.id,'%(asx_code)s')
>
> db.prices.share_id.writable = db.prices.share_id.readable = False
>
>
> ---index in default.py---
>
> def index():
>    shares=db().select(db.shares.ALL, orderby=db.shares.asx_code)
>    return dict(shares=shares)
>
>
> ---default/index.html---
>
> {{extend 'layout.html'}}
> <h1>Share portfolio</h1>
> <ul>
> {{for asx_code in shares:}}
> {{=LI(shares.asx_code)}}
> {{pass}}
> </ul>
>
>
> What am I doing wrong? i'm a bit confused with variables in the
> controller, I have a table called shares, a variable declared in the
> controller called shares and the value in the dictionary called shares
> so it's very hard to know what I'm calling / using in the view!!! (the
> LI code could be wrong, I couldn't get it to show anything to debug
> that far). shares table contains two entries.
>
> Thanks!
>

Reply via email to