本文整理匯總了Python中jinja2.Template.globals['now']方法的典型用法代碼示例。如果您正苦於以下問題:Python Template.globals['now']方法的具體用法?Python Template.globals['now']怎麽用?Python Template.globals['now']使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類jinja2.Template
的用法示例。
在下文中一共展示了Template.globals['now']方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: Template
# 需要導入模塊: from jinja2 import Template [as 別名]
# 或者: from jinja2.Template import globals['now'] [as 別名]
import datetime
import math
from jinja2 import Template
from sqlalchemy import and_
from server import models, db
from server.models import Match, Bet, User
template = Template("""
# Generation started on {{ now() }}
... this is the rest of my template...
# Completed generation.
""")
template.globals['now'] = datetime.datetime.utcnow
def add_match(tournament, home_team, away_team, time_start):
match = models.Match(tournament=tournament, home_team=home_team, away_team=away_team, time_start=time_start)
db.session.add(match)
db.session.commit()
def get_match_by_id(match_id):
return Match.query.filter(Match.id == match_id).first()
def get_nearest_matches_and_bets_by_user(user_id):
now = datetime.datetime.utcnow()
return db.session.query(Match, Bet) \
.outerjoin(Bet, and_(Bet.match_id == Match.id, Bet.user_id == user_id)) \
.filter(Match.time_start > now) \