From 9133512ec121a6e8f256ff5007bb647fb28f0838 Mon Sep 17 00:00:00 2001 From: Castro0o Date: Wed, 25 Mar 2020 16:34:14 +0100 Subject: [PATCH] playing wiht Jinja --- query2html.py | 5 +++++ sandbox/jinja_tutorial.py | 15 +++++++++++++++ templates/scatch.html | 13 +++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 sandbox/jinja_tutorial.py create mode 100644 templates/scatch.html diff --git a/query2html.py b/query2html.py index d00dc70..0d51119 100644 --- a/query2html.py +++ b/query2html.py @@ -96,6 +96,11 @@ for answer in site.ask(query): pagetext_html = pandoc(pwd=wd, content=pagetext, format_in='mediawiki', format_out='html') img_local = os.path.join(imgdir, img_info.get('filename')) + # Todo: Create list of all images from document + # TODO: join document_part + document + # TODO: look into the template structure of images : columns and rows + + # RENDER document part document_part_html = document_part_template.render( printout_dict=printout_dict, diff --git a/sandbox/jinja_tutorial.py b/sandbox/jinja_tutorial.py new file mode 100644 index 0000000..10eb21c --- /dev/null +++ b/sandbox/jinja_tutorial.py @@ -0,0 +1,15 @@ +import os +from jinja2 import Template + +wd = os.path.dirname(os.path.abspath(__file__)) # working directory + +# read template files +with open(os.path.join(wd, '../templates/scatch.html')) as document_html: + template = Template(document_html.read()) + +imgs_list = ['images/01.jpg', 'images/02.jpg', 'images/03.jpg'] + +template_render = template.render(title=':) Hello Sandra', + imgs=imgs_list + ) +print(template_render) \ No newline at end of file diff --git a/templates/scatch.html b/templates/scatch.html new file mode 100644 index 0000000..0ca2714 --- /dev/null +++ b/templates/scatch.html @@ -0,0 +1,13 @@ +

{{ title|upper }}

+ +
+
+ + {% for img in imgs %} + + {% endfor %} + +
+
+ +{{imgs}} \ No newline at end of file