Note, you are using a non-Ajax component. I'm not sure why 
request.user_agent isn't defined in that case, but there are some funky 
things going on with non-Ajax components, so I would instead recommend 
using Ajax components:

{{=LOAD('service', 'serv1', ajax=True)}}

Feel free to file a Google Code issue about user_agent not work with 
non-Ajax components.

Anthony

On Wednesday, July 16, 2014 5:06:44 PM UTC-4, Louis Amon wrote:
>
> Sure. It's fairly simple tho since the Exception gets raised on line 1 of 
> my LOADed view.
>
> Views/default/search.html:
> ...
> {{ =LOAD('service', 'serv1') }}
> ...
>
>
> Controllers/service.py:
> response.view = "service.load" 
>
> def serv1():  
>     return dict()
>
>
> Views/service.load :
> {{ is_mobile = request.user_agent().is_mobile }}
> ...
>
>
> Ticket :
>
> Traceback (most recent call last):
>  File "/Users/atomos/Desktop/W2P/web2py-master/gluon/restricted.py", line 
> 220, in restricted
>  exec ccode in environment
>  File 
> "/Users/atomos/Desktop/W2P/web2py-master/applications/mbpd/views/service.load",
>  line 1, in <module>
>  {{ is_mobile = request.user_agent().is_mobile }}
> TypeError: 'NoneType' object is not callable
>
>
> On Wednesday, July 16, 2014 10:48:23 PM UTC+2, Anthony wrote:
>>
>> Please show your code and the exception.
>>
>> On Wednesday, July 16, 2014 4:15:27 PM UTC-4, Louis Amon wrote:
>>>
>>> I'm a great fan of LOAD, and i'm using it quite a bit to generate cool 
>>> ajax pages.
>>>
>>> I got one issue so far though : can't seem to *cleanly* detect a mobile 
>>> device in a .load view.
>>>
>>> For example I have a "result.load" view and I want a special mobile 
>>> display in "result.mobile.load".
>>>
>>> I've tried to use the decorator @mobilize but it seems that user_agent() 
>>> raises an Exception when called from a LOADed view.
>>>
>>> Is there a clean way to do that ?
>>>
>>>
>>> For those who, like me, are struggling over this, there is a monkeypatch 
>>> :
>>>
>>> In the controller/view that calls LOAD(...):
>>> LOAD(..., vars=dict(is_mobile=request.user_agent().is_mobile))
>>>
>>> In the LOADed view:
>>> is_mobile = (request.vars.is_mobile == 'True')
>>>
>>>

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