On Thursday, December 27, 2018 at 4:05:40 PM UTC-5, Vlad wrote:
>
> Here is a test function in my controller: 
>
> def test():
>     id = 0
>     try:
>         id = request.args(0, cast=int)
>         session.flash = "Here is the id: " + str(id)
>     except:
>         session.flash = "ID is not valid!"
>         pass
>     if id==0:
>         redirect(URL('home'))
>     query = db.test_table.id == id
>     grid = SQLFORM.grid(query, db.test_table, user_signature=False)
>     return locals()
>

Regarding the flash message, you should be setting response.flash, not 
session.flash (the latter goes in the session and will not be displayed 
until the *next *request, as you have observed -- it is typically used just 
before a redirect).

What are you attempting to do with this function? Why are you even using 
the grid if you are only intending to display a single record?

Note, your code does nothing in case the request.args(0) is not a valid 
integer -- in that case, your function still returns a grid (though 
presumably using a query you don't want). You might instead want to do a 
redirect in that case.

Also, if your function is going to make use of some of the URL args, you 
must indicate this to the grid by passing in the URL args it is supposed to 
use (via the "args" argument).

Finally, actions other than reading data require either a logged in user or 
user_signature=False.

Anthony

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
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/d/optout.

Reply via email to