Hi Anthony,
I almost missed your post.  I didn't know this.  
Thanks!


On Monday, 24 June 2013 02:52:01 UTC+1, Anthony wrote:
>
> FYI, you can do:
>
> myint = request.args(0, default=0, cast=int, otherwise='http://error_url')
>
> The default value is returned if there is no arg at the index specified. 
> If there is an arg, it attempts to use the function provided in cast to 
> convert the arg. If that fails, it redirects to the URL specified in 
> otherwise.
>
> I think all but the "default" argument is documented here: 
> http://web2py.com/books/default/chapter/29/03?search=cast#An-image-blog, 
> though would probably make sense to add documentation to the Core chapter 
> where request.args is discussed, as the Overview chapter is a tutorial and 
> not intended as a reference.
>
> Anthony
>
> On Sunday, June 23, 2013 6:26:04 PM UTC-4, villas wrote:
>>
>> However, I must admit,  as there isn't a built in function,  I find the 
>> code more transparent like this...
>>
>> try:
>>     myint = int(request.args(0))
>> except:
>>     myint = None
>>
>> or if we are testing whether this is a valid id...
>>
>> myvalidrecord = db.mytable(request.args(0))
>> If not myvalidrecord:
>>     session.flash = 'record not found'
>>     redirect(URL())
>>
>> I suppose it's mainly a question of personal preference,  but,  having 
>> functions calling other functions can cause confusion when you posting code 
>> to the group.
>> Thanks,  D
>>
>

-- 

--- 
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.


Reply via email to