From 9573bb498484b4796f238dee58d44f61c22b1dd5 Mon Sep 17 00:00:00 2001 From: Castro0o Date: Mon, 4 Mar 2019 18:08:36 +0100 Subject: [PATCH] introduction to jinja files --- Jinja-prototype/base.html | 13 +++++++ Jinja-prototype/child.html | 9 +++++ Jinja-prototype/createhtml.py | 52 +++++++++++++++++++++++++++ Jinja-prototype/index.html | 68 +++++++++++++++++++++++++++++++++++ Jinja-prototype/style.css | 7 ++++ 5 files changed, 149 insertions(+) create mode 100644 Jinja-prototype/base.html create mode 100644 Jinja-prototype/child.html create mode 100644 Jinja-prototype/createhtml.py create mode 100644 Jinja-prototype/index.html create mode 100644 Jinja-prototype/style.css diff --git a/Jinja-prototype/base.html b/Jinja-prototype/base.html new file mode 100644 index 0000000..801553b --- /dev/null +++ b/Jinja-prototype/base.html @@ -0,0 +1,13 @@ + + + + + {% block title %}{% endblock %} + + +
+ {% block content %} + {% endblock %} +
+ + \ No newline at end of file diff --git a/Jinja-prototype/child.html b/Jinja-prototype/child.html new file mode 100644 index 0000000..e1f7e46 --- /dev/null +++ b/Jinja-prototype/child.html @@ -0,0 +1,9 @@ +{% extends "base.html" %} + +{% block title %}{{ mytitle }}{% endblock %} + +{% block content %} +
+ {{ content }} +
+{% endblock %} \ No newline at end of file diff --git a/Jinja-prototype/createhtml.py b/Jinja-prototype/createhtml.py new file mode 100644 index 0000000..74034a4 --- /dev/null +++ b/Jinja-prototype/createhtml.py @@ -0,0 +1,52 @@ +from jinja2 import Template + + +# render template +# http://jinja.pocoo.org/docs/2.10/intro/#basic-api-usage + +# htmlfragment = """ +# {{ content }} +# """ +# template = Template(htmlfragment) +# htmlrendered = template.render(content="Jinja What??", +# id="iamid") +# print(htmlrendered) + +xpub1 = ["Pedro","Rita","Simon","Artemis","Bo","Biyi"] +xpub2 = ["Tash", "Angeliki","Alice","Alex", "Joca", "Zalan"] +users_html = Template(''' +''') + +users_1 = users_html.render(users=xpub1) +users_2 = users_html.render(users=xpub2) +print(users_1, users_2) + + +# template-inheritance +# http://jinja.pocoo.org/docs/2.10/templates/#template-inheritance +from jinja2 import FileSystemLoader +from jinja2.environment import Environment + +env = Environment() +env.loader = FileSystemLoader('.') +tmpl = env.get_template('child.html') +tmpl_render= tmpl.render(mytitle="xpUB", + content=users_1 + users_2) +print(tmpl_render) + +# save +with open("index.html","w") as index: + index.write(tmpl_render) + + +# contro structures +# http://jinja.pocoo.org/docs/2.10/templates/#list-of-control-structures + + +# print(users_html.render(users=xpub)) \ No newline at end of file diff --git a/Jinja-prototype/index.html b/Jinja-prototype/index.html new file mode 100644 index 0000000..964bb6f --- /dev/null +++ b/Jinja-prototype/index.html @@ -0,0 +1,68 @@ + + + + + xpUB + + +
+ +
+
    + +
  • + Pedro +
  • + +
  • + Rita +
  • + +
  • + Simon +
  • + +
  • + Artemis +
  • + +
  • + Bo +
  • + +
  • + Biyi +
  • + +
    + +
  • + Tash +
  • + +
  • + Angeliki +
  • + +
  • + Alice +
  • + +
  • + Alex +
  • + +
  • + Joca +
  • + +
  • + Zalan +
  • + +
+
+ +
+ + \ No newline at end of file diff --git a/Jinja-prototype/style.css b/Jinja-prototype/style.css new file mode 100644 index 0000000..97b8dfa --- /dev/null +++ b/Jinja-prototype/style.css @@ -0,0 +1,7 @@ +.box{ background: black; +color:white; + } + +.user{color:yellow; + text-decoration: underline; +} \ No newline at end of file