-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
35 lines (26 loc) · 1.03 KB
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from dotenv import load_dotenv
load_dotenv()
# -*- Sanic configg 4 fest deploiment -*-
from sanic import Sanic
app = Sanic("HeadsInTheCloud2")
app.static('/static', './static')
# -*- Jinja2 setup -*-
from jinja2 import Environment, PackageLoader, select_autoescape
J2env = Environment(loader=PackageLoader('server', './templates'),
autoescape=select_autoescape(['html', 'xml']),
enable_async=True)
J2env.globals["url_for"] = app.url_for
app.J2env = J2env
# -*- Sanic Extensions -*-
from sanic.exceptions import SanicException
from sanic.response import html
@app.exception(SanicException)
async def catch_exceptions_4xx_5xx(req, excp):
template = J2env.get_template('/pages/Error_4xx_5xx.jinja2')
_html = await template.render_async(title="What in tarnation... | HITC2")
return html(_html)
# -*- Blueprint Registration -*-
from blueprints.HeaderBrowser import HeaderBrowserBP
app.blueprint(HeaderBrowserBP)
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8000, debug=True, workers=2)