[NTG-context] Django: using ConTeXT mkiv to output PDF

kaddour kardio kaddourkardio at gmail.com
Fri Jan 26 19:41:19 CET 2018


>
> def courrier_mkiv(request, pk2, pk1):
>     entry = Courrier.objects.get(pk=pk2)
>     cource = Patient.objects.get(pk=pk1)
>     context = dict({'courrier': entry, 'patient': cource})
>     # buffer = BytesIO()
>     template = get_template('courrier/courrier.mkiv')
>     rendered_tpl = template.render(context, request).encode('utf-8')
>     with tempfile.TemporaryDirectory() as tempdir:
>     # mtxrun --path=/data/foo --script context
>         process = Popen(['mtxrun', '--path', tempdir,
>                         '--script=context'
>                         '--result'],
>                         stdin=PIPE,
>                         stdout=PIPE,
>                         )
>         process.communicate(rendered_tpl)
>     with open(os.path.join(tempdir, 'textput.pdf'), 'rb') as f:
>         pdf = f.read()
>     r = HttpResponse(content_type='application/pdf')
>     r.write(pdf)
>     return r


i tried this without success :(
the only workaround u've found for now is to render a tex file and copile
it manually.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ntg.nl/pipermail/ntg-context/attachments/20180126/b9e3fe00/attachment.html>


More information about the ntg-context mailing list