Open jhancke opened 2 years ago
I made up a minimal example to reproduce this error.
I have a template custom
which lives in /usr/local/share/jupyter/nbconvert/templates/custom
:
custom/
-- conf.json
-- index.html.j2
conf.json
{
"base_template": "classic",
"mimetypes": {
"text/html": true
},
"preprocessors": {
"100-pygments": {
"type": "nbconvert.preprocessors.CSSHTMLHeaderPreprocessor",
"enabled": true,
"style": "default"
}
}
}
{%- extends 'classic/index.html.j2' -%}
{% block footer %}
FOOOOOOOOTEEEEER
{% endblock footer %}
Some code to convert notebooks:
import json
from nbconvert import HTMLExporter
import nbformat
class MyExporter(HTMLExporter):
template_file = 'custom/index.html.j2'
def read_notebook(path):
with open(path) as json_file:
data = json_file.read()
json_body = json.loads(data)
return nbformat.reads(json.dumps(json_body), 4)
if __name__ == '__main__':
path = ''
notebook = read_notebook(path)
my_exporter = MyExporter()
(body, resources) = my_exporter.from_notebook_node(notebook)
print(body)
I also tried using classic template directly:
class MyExporter(HTMLExporter):
template_file = 'classic/index.html.j2'
Which also fails with the same error.
I also found out that when using template_name=classic
or template_name=custom
the issue does not happen.
this could be related: https://github.com/jupyter/nbconvert/pull/1827
How was this issue resolved?
Using nbconvert from the code, there is an error when inheriting from the
classic
template, stating that thestatic/style.css
can't be found.The custom template was put beside the other templates in
/usr/local/share/jupyter/nbconvert/templates
It contains a .conf file stating that the base template is classic and a template including{%- extends 'classic/index.html.j2' -%}
When converting the notebook by calling
html_exporter.from_notebook_node(notebook)
the error is thrown:HTML_EXPORTER
with a custom template.classic/index.html.j2
Nbconvert version: 7.0