As a test remove the promobox=box item from the dict returned from the
controller and put this
{{print globals().keys()}}
in the view file before the failure and check the output on the
console. This is also assuming you are running in developer mode with
the rocket web server.
You will likely find 'promobox' in the list printed out, probably
defined somewhere in the module or model files. The assignment
promobox=box inside the dict constructor in the controller is covering
up an already existing global dictionary item that has key 'promobox'.
It will also likely be a function definition. This causes the if
'promobox' in globals(): to always pass the test as true and an
attempt to take the index gives you the error.
On Oct 17, 12:16 am, annet <[email protected]> wrote:
> > This error makes sense, promobox is an empty list and
> > any attempt to index it (as in promobox[0]) will give the error.
> > Note that is different from the error in your first post.
>
> Yes, but I had hoped that this function:
>
> @auth.requires_login()
> def index():
> if auth.user.account!='1':
> redirect(URL(r=request,c='view',f='index'))
> else:
> response.functionname='Business Card'
> return dict()
>
> .. and this view:
>
> {{if 'promobox' in globals():}}
> <div class="sidebox">
> {{if promobox[0].kop:}}
> <h3>{{=promobox[0].kop}}</h3>
> {{pass}}
> {{=XML(promobox[0].tekst)}}
> </div> <!-- sidebox -->
> {{pass}}
>
> .. would, in case of re-using views, prevent me from returning empty
> lists to the view for every variable in the view I do not assign a
> value to in the function.
>
> I solved the problem using the last function, but I was curious why
> the function and view in the first post result in: TypeError:
> 'function' object is unsubscriptable.
>
> Kind regards,
>
> Annet.