def test_use_templates_throws_for_invalid_services(): app = Application(services={}) # type: ignore with pytest.raises(TypeError): use_templates(app, loader=PackageLoader("tests.testapp", "templates"), enable_async=False)
def test_application_use_templates_with_services(): app = Application(services=Services()) use_templates(app, loader=PackageLoader("tests.testapp", "templates"), enable_async=False) assert isinstance(app.services, Services) assert app.services["jinja_environment"] is not None
def configure_templating(application: Application, configuration: Configuration): use_templates(application, PackageLoader(__name__, 'views')) def get_copy(): now = datetime.now() return "{} {}".format(now.year, configuration.site.copyright) helpers = { '_': lambda x: x, 'copy': get_copy } # noinspection PyUnresolvedReferences env = application.jinja_environment # type: Environment env.globals.update(helpers)
def configure_templating(application: Application, configuration: Configuration) -> None: """ Configures server side templating engine for HTML views, using Jinja2. """ use_templates(application, PackageLoader("app", "views")) def get_copy(): now = datetime.now() return "{} {}".format(now.year, configuration.site.copyright) helpers = {"_": lambda x: x, "copy": get_copy} env: Environment = application.jinja_environment # type: ignore env.globals.update(helpers)
def get_app(enable_async): app = FakeApplication() render = use_templates(app, loader=PackageLoader('tests.testapp', 'templates'), enable_async=enable_async) return app, render
from blacksheep.server.bindings import Request from blacksheep.server.templating import use_templates from blacksheep.server.responses import redirect, status_code, text, json as res_json from jinja2 import PackageLoader from event import Event from fips import get_fips import json from event_risk import event_risk import database as db from datetime import datetime, date from nanoid import generate app = Application() get = app.router.get post = app.router.post view = use_templates(app, loader=PackageLoader('app', 'templates')) @app.route('/') def home(): return view('index', {}) @app.route('/create-event') def create_event(): return view('create-event', {}) @get('/event-layout') def event_layout(id: str, seats: int): evt = db.load_event(id)