def render(template_name, **kwargs): from template import MiniTemplate app = app_stack.head if app.template_path is None: app.template_path = os.getcwd() full_path = os.path.join(app.template_path, app.template_folder, template_name) tpl = MiniTemplate(full_path) return tpl.render(**kwargs)
from web import Minim, render, request, response from template import MiniTemplate from models import Person from io import BytesIO app = Minim() greetings = 'The world is my idea~' MiniTemplate.inject_context('greetings', greetings) @app.get('/favicon.ico') def favicon(): return '' @app.get('/') def index(): request.foo = 'bar' persons = Person.select() # print(request.foo) welcome = 'Keep calm and carry on!' motto = ['醒醒我们回家了', '世界是我的表象', '向死而生', '凡人所有的我都有'] # print('host', request.host) # print('host-port', request.host_port) # print('path', request.path) # print('fullpath', request.full_path) # print('script-root', request.script_root) # print('url', request.url) # print('base-url', request.base_url) # print('url-root', request.url_root) # print('host-url', request.host_url)