Skip to content

Commit

Permalink
Add jinja and html template
Browse files Browse the repository at this point in the history
  • Loading branch information
aysin committed May 14, 2017
1 parent e864b79 commit 8b24d49
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ services:
web:
build: .
ports:
- "5000:8080"
- "8080:8080"
volumes:
- .:/code
elasticsearch:
Expand Down
17 changes: 13 additions & 4 deletions optical/app.py
Original file line number Diff line number Diff line change
@@ -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)
5 changes: 5 additions & 0 deletions optical/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!doctype html>
<title>{{ title }}</title>
<div class=page>
<h1>hello, {{ name }}</h1>
</div>
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Sanic
elasticsearch
elasticsearch-dsl
ipython
ipython
Jinja2

0 comments on commit 8b24d49

Please sign in to comment.