diff --git a/docker-compose.yml b/docker-compose.yml index f87827c..5d7c060 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,7 +3,7 @@ services: web: build: . ports: - - "5000:8080" + - "8080:8080" volumes: - .:/code elasticsearch: diff --git a/optical/app.py b/optical/app.py index 3f8255e..d1867e8 100644 --- a/optical/app.py +++ b/optical/app.py @@ -1,14 +1,23 @@ from sanic import Sanic -from sanic.response import json +from sanic.response import json, html, text from elasticsearch import Elasticsearch +from jinja2 import Environment, PackageLoader client = Elasticsearch(hosts=['elasticsearch'], http_auth=('elastic', 'changeme',)) -app = Sanic() +env = Environment(loader=PackageLoader('app', 'templates')) -@app.route("/") +app = Sanic(__name__) + +@app.route('/') async def test(request): - return json({"hello": "world"}) + data = {'name': 'Aysin'} + + template = env.get_template('index.html') + html_content = template.render(name=data["name"]) + # content=template.render(title='Sanic',people='David') + return html(html_content) + if __name__ == "__main__": app.run(host="0.0.0.0", port=8080) diff --git a/optical/templates/index.html b/optical/templates/index.html new file mode 100644 index 0000000..5ab841e --- /dev/null +++ b/optical/templates/index.html @@ -0,0 +1,5 @@ + +{{ title }} +
+

hello, {{ name }}

+
\ No newline at end of file diff --git a/requirements.txt b/requirements.txt index b6e346d..dcc279e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ Sanic elasticsearch elasticsearch-dsl -ipython \ No newline at end of file +ipython +Jinja2 \ No newline at end of file