thank you! will try shortly

On Feb 21, 6:45 pm, Anthony <[email protected]> wrote:
> On Monday, February 21, 2011 9:08:16 PM UTC-5, darkblue_b wrote:
>
> > I guess I am still missing something..
> > I wrote this, but, logged in, I get a msg that says "no json" and a
> > blank screen
>
> > ##-- controllers/data_hose.py
> > from gluon.serializers import json
>
> > @auth.requires_login()
>
> > ##------------------------------------
> > def get_data():
> >   sample_data = { 'key1' : 'response 1' }
> >   return sample_data
>
> > def data_as_json():
> >   stuff = get_data()
> >   return json( stuff )
>
>  @auth.requires_login() is a Python decorator, so you have to put it on the
> line immediately before the function you want to decorate -- in this case:
>
> @auth.requires_login()
> def data_as_json():
>   stuff = get_data()
>   return json(stuff)
>
> Seehttp://web2py.com/book/default/chapter/08#Decoratorsfor more details.
>
> Also, any function in your controller file that takes no arguments or
> doesn't start with two underscores can be accessed via a URL request, so you
> may not want a function like get_data() in your controller. If the sole
> purpose of that function is to be called by other functions (such as
> data_as_json), then you should either start it with two underscores (i.e.,
> def __get_data()), make sure it takes at least one argument (e.g., def
> get_data(dummy_arg)), or import it from a module. For more details, 
> seehttp://web2py.com/book/default/chapter/04#Dispatching.
>
> Anthony

Reply via email to