Commit a1df4bd7 authored by Nadine Tschirner's avatar Nadine Tschirner
Browse files

app.py : yaml in jinja gerendert

parent 35afa59e
from flask import render_template
from jinja2 import Template
from flask import Flask
from flask import Flask, request, redirect, url_for
import yaml
import json
app = Flask(__name__)
@app.route('/')
def in_yml():
with open("host.yml", 'r') as host:
return host.read()
#@app.route('/')
#def in_yml():
# with open("host.yml", 'r') as host:
# return host.read()
#env = Environment(loader = FileSystemLoader('./templates'), print(template.render(host.yml)))
@app.route('/test01')
def test_jinja01():
tm = Template('Hallo Welt')
output = tm.render()
return output
#@app.route('/test01')
#def test_jinja01():
# tm = Template('Hallo Welt')
# output = tm.render()
# return output
@app.route('/test01_1')
def test_jinja01_1():
tm = Template('Hallo {{ name }}')
output = tm.render(name='Nadine')
return output
#@app.route('/test01_1')
#def test_jinja01_1():
# tm = Template('Hallo {{ name }}')
# output = tm.render(name='Nadine')
# return output
@app.route('/test01_2')
def test_jinja01_2():
name_python='Megisjana'
tm = Template('Hallo {{ name_jinja }}')
output = tm.render(name_jinja=name_python)
return output
#@app.route('/test01_2')
#def test_jinja01_2():
# name_python='Megisjana'
# tm = Template('Hallo {{ name_jinja }}')
# output = tm.render(name_jinja=name_python)
# return output
@app.route('/test01_3')
def test_jinja01_3():
name_list=['Megisjana', 'Nadine']
tm = Template('Hallo {{ name_jinja }}')
output = tm.render(name_jinja=name_list[1])
return output
#@app.route('/test01_3')
#def test_jinja01_3():
# name_list=['Megisjana', 'Nadine']
# tm = Template('Hallo {{ name_jinja }}')
# output = tm.render(name_jinja=name_list[1])
# return output
@app.route('/test02')
def test_jinja02():
with open("test.html", 'r') as template_jinja:
tm = Template(template_jinja.read())
return tm.render()
#@app.route('/test02')
#def test_jinja02():
# with open("test.html", 'r') as template_jinja:
# tm = Template(template_jinja.read())
# return tm.render()
@app.route('/test03')
def in_yml03():
with open("host.yml", 'r') as host1:
dict = yaml.safe_load(host1)
return dict
print(dict)
#@app.route('/test03')
#def in_yml03():
# with open("host.yml", 'r') as host1:
# dict = yaml.safe_load(host1)
# return dict
# print(dict)
@app.route('/test04')
def in_yml04():
with open("host.yml", 'r') as yaml_in, open("host.json","w") as json_out:
yaml_object = yaml.safe_load(yaml_in)
json.dump(yaml_object, json_out)
#@app.route('/test04')
#def in_yml04():
# with open("host.yml", 'r') as yaml_in, open("host.json","w") as json_out:
# yaml_object = yaml.safe_load(yaml_in)
# json.dump(yaml_object, json_out)
@app.route('/last')
def parse():
with open("host.yml", "r") as host:
data = yaml.load(host, Loader=yaml.FullLoader)
with open("test.html", "r") as jinja_template:
tm = Template(jinja_template.read())
return tm.render(yml=data)
if __name__ == '__main__':
app.run(host='0.0.0.0', debug=True)
......@@ -7,8 +7,12 @@
</head>
<body>
<p>
{% for networks in network %}
The hostname is {{ ['name'] }}
{{ yml }}
</p>
<p>
{% for network in yml.network %}
The hostname is {{ network.name }}<br>
The IP is {{ network.ip }}<br>
{% endfor %}
</p>
</body>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment