-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviews.py
27 lines (22 loc) · 874 Bytes
/
views.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
import os
from jinja2 import Environment, PackageLoader, select_autoescape
env = Environment(
loader=PackageLoader(__name__, 'templates'),
autoescape=select_autoescape(['html', 'xml'])
)
def screen_cleaner(flag):
if flag:
os.system('cls' if os.name == 'nt' else 'clear')
def render_template(context=None, template="default.jinja2", cls=True):
"""Prints rendered template with context data
Args:
context (dict, optional): [data for rendering template]. Defaults to None.
template (str, optional): [template filename]. Defaults to "default.jinja2".
cls (bool, optional): [Clear screen flas. Shows if screan should be
cleaned before showing this view]. Defaults to True.
"""
if not context:
context = {}
screen_cleaner(cls)
template = env.get_template(template)
print(template.render(**context))