Oh ok perfect thanks for the note. I was able to do so by preparing the 
structure in the back-end. 
Really appreciate the respond. Yes next time will do it through js. 


On Sunday, May 11, 2014 5:33:39 PM UTC-4, Blaise Laflamme wrote:
>
> Hello Yannick,
>
> it's hard to answer your question because we miss to know what you're 
> trying to do. If you return a view with a json renderer the output will be 
> json, not html. If you return a view with a jinja2 renderer the output will 
> be html, not json. Jinja2 can iterate over a python list but not over a 
> json list, so it's hard to understand what you're trying to achieve here? 
> Json is for javascript so if you directly pass json to your html view it's 
> probably to init a javascript variable? Or you'd be better to call an API 
> to get that list from your javascript code.
>
> To display json in your jinja2 templates, I'm a mako guy so I can be 
> wrong, I think it should be something like: {{myvariable|safe}}
>
> OTOH if you want to return json but the result from the db is not what you 
> want to expose, you'll have to prepare the structure before sending it to 
> the view. 
>
> On Sunday, May 11, 2014 1:06:02 PM UTC-4, Yannick wrote:
>>
>> Hello mate,
>>
>> I want to display a JSON in the view and here is what I do:
>> *- In the view.py:*
>> @view_config(route_name='display', renderer='json' )#, 
>> renderer='templates/display_user.jinja2')
>> def display_user(request):
>>        * # I get listUser from the DB*
>> *        # I print the listUser  and I can see the list in the terminal*
>>         print dumps(listUser)
>> return {'listUser':  dumps(listUser)}
>>
>> *- In the display_user.jinja2, here is what I do:*
>> {% for user in listUser %}
>>   {{ user}}
>> {% endfor %}
>>
>> _____________
>> When I run the code nothing is display in the front-end. Is shows an 
>> empty JSON which doesn't make sense to me because in the back-end I can see 
>> the list when I do the print.
>>
>> Thank You for your help
>> Yannick P.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pylons-discuss.
For more options, visit https://groups.google.com/d/optout.

Reply via email to