Craig,

The subprocess is returning a json-encoded string. This is a string. You
must parse it first via json.loads(subprocess.check_output(...)) if you
want to use the objects it contains in your template. Similarly you said
it's working with renderer="json" but it's actually not. You're
json-encoding a json-encoded string. You'll see if you try to use that
response that it is double encoded and you will need to double-decode it.
You'll want to use the same solution in that case via json.loads() or you
can just pass through the check_output content as the response body by
making a response yourself instead of using the renderer.

- Michael

On Tue, Feb 13, 2018 at 6:03 AM, Craig Burton <
craig.alexander.bur...@gmail.com> wrote:

> Hi there, if you can help me with this it will save what's left of my hair.
>
> I want to have a jinja2 template render with variables passed in from an
> external program.  The views.py has this in it
>
> @view_config(route_name='stats', renderer='templates/stats.jinja2')
> def my_view_stats(request):
> return {'r': subprocess.check_output(['program_that_returns_json']),
> 'page': 'My Stats', 'next' : '/hello', 'prev': '/paydown'}
>
> program_that_returns_json returns this kind of thing {'on_target' : 3425}
>
> The template stats.jinja2 has
> We are this much on target: {{r.on_target}}
> ...
> The next page is {{next}}
>
> {{next}} gets rendered but {{r.on_target}} does not.
>
> The technique above works for me when renderer='json' but I need
> javascript to unpack the response and jquery to set content, variable by
> variable.  Here I have a large list of them.  Can it work like I have
> guessed or ?
> Cheers
> Craig.
>
> --
> 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 pylons-discuss+unsubscr...@googlegroups.com.
> To post to this group, send email to pylons-discuss@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/pylons-discuss/7541dfdb-307f-46a6-9c0e-1c755fc64295%
> 40googlegroups.com
> <https://groups.google.com/d/msgid/pylons-discuss/7541dfdb-307f-46a6-9c0e-1c755fc64295%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 pylons-discuss+unsubscr...@googlegroups.com.
To post to this group, send email to pylons-discuss@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pylons-discuss/CAKdhhwEuOc0OYcAUKF5V5qAWGq%3Dww%3DyN4GvcDL%3DBXPmstv48%2Bg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to