[IPython-dev] Problems using nbconvert with custom templates in IPython2.0-rc1
Jones, Zach H
Zach.Jones at netapp.com
Sun Mar 30 00:05:46 EDT 2014
I have made some progress in debugging the problems.
The error with the na_full template was that html_basic.tpl is now basic.tpl. After correcting to {%- extends basic.tpl -%} my template is working again.
It looks like the na_report template not being recognized is because there is a error that occurs when loading the template inside nbconvert.
Are the silent errors by design? Is there a way for me to invoke verbose output during the loading the templates?
Thanks,
Zach Jones
________________________________
From: ipython-dev-bounces at scipy.org [ipython-dev-bounces at scipy.org] on behalf of Jones, Zach H [Zach.Jones at netapp.com]
Sent: Saturday, March 29, 2014 8:27 PM
To: ipython-dev at scipy.org
Subject: [IPython-dev] Problems using nbconvert with custom templates in IPython2.0-rc1
All,
I have been using nbconvert to generate HTML views of notebooks with IPython1.x. I based my work on this: http://nbviewer.ipython.org/urls/raw.githubusercontent.com/ipython/ipython-in-depth/master/notebooks/07%20-%20NbConvert%20Python%20library.ipynb?create=1#Programatically-make-templates
This work great with IPython1.x but is now not working with IPython2.0-rc. I am hoping you can help me sort through my errors.
The code looks like this:
extra_tpls = DictLoader({'na_full': ..., 'na_report', ...})
c = Config()
c.HTMLExporter.default_template = 'na_report'
exportHTML = HTMLExporter(config=c, extra_loaders=[extra_tpls])
exportHTML.from_notebook_node(nb)
My DictLoader contains two templates:
* na_full extends html_basic.tpl
* na_report extends display_priority.tpl
I get errors with either template, but each template is different.
For na_full, it looks like html_basic.tpl cannot be found:
---------------------------------------------------------------------------
TemplateNotFound Traceback (most recent call last)
<ipython-input-23-008e826165f9> in <module>()
----> 1 exportHTML.from_notebook_node(nb)
/x/eng/rtpperf/python2.7-Debian-unstable-x86_64-tst/local/lib/python2.7/site-packages/IPython/nbconvert/exporters/templateexporter.pyc in from_notebook_node(self, nb, resources, **kw)
213
214 if self.template is not None:
--> 215 output = self.template.render(nb=nb_copy, resources=resources)
216 else:
217 raise IOError('template file "%s" could not be found' % self.template_file)
/x/eng/rtpperf/python2.7-Debian-unstable-x86_64-tst/local/lib/python2.7/site-packages/jinja2/environment.pyc in render(self, *args, **kwargs)
967 except Exception:
968 exc_info = sys.exc_info()
--> 969 return self.environment.handle_exception(exc_info, True)
970
971 def stream(self, *args, **kwargs):
/x/eng/rtpperf/python2.7-Debian-unstable-x86_64-tst/local/lib/python2.7/site-packages/jinja2/environment.pyc in handle_exception(self, exc_info, rendered, source_hint)
740 self.exception_handler(traceback)
741 exc_type, exc_value, tb = traceback.standard_exc_info
--> 742 reraise(exc_type, exc_value, tb)
743
744 def join_path(self, template, parent):
<template> in top-level template code()
TemplateNotFound: html_basic.tpl
For na_report, it looks like that it is not being found:
---------------------------------------------------------------------------
IOError Traceback (most recent call last)
<ipython-input-20-008e826165f9> in <module>()
----> 1 exportHTML.from_notebook_node(nb)
/x/eng/rtpperf/python2.7-Debian-unstable-x86_64-tst/local/lib/python2.7/site-packages/IPython/nbconvert/exporters/templateexporter.pyc in from_notebook_node(self, nb, resources, **kw)
215 output = self.template.render(nb=nb_copy, resources=resources)
216 else:
--> 217 raise IOError('template file "%s" could not be found' % self.template_file)
218 return output, resources
219
IOError: template file "html_na_report" could not be found
I have also tried using the FileSystemLoader from jinja2 as well. It loads the templates and I get the same errors.
Thanks for your help,
Zach Jones
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20140330/e4521a9d/attachment.html>
More information about the IPython-dev
mailing list