本文整理汇总了Python中jinja2.Template.name方法的典型用法代码示例。如果您正苦于以下问题:Python Template.name方法的具体用法?Python Template.name怎么用?Python Template.name使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jinja2.Template
的用法示例。
在下文中一共展示了Template.name方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sendcaserequest
# 需要导入模块: from jinja2 import Template [as 别名]
# 或者: from jinja2.Template import name [as 别名]
def sendcaserequest():
import time
session["result"] = {
"messages":[],
"successChecks":[],
"failedChecks":[]
}
info = {"result":True,"errorMsg":None,"ok":None,"success":0,"failed":0,"messages":None}
apiid = int(request.form.get("apiid"))
api = Api.query.filter_by(id=apiid).first()
name = request.form.get("name").strip()
desc = request.form.get("desc").strip()
script = request.form.get("script").strip()
purpose = request.form.get("purpose")
if purpose == "run":
actionParser = parseScript(script)
case = Template(case_template).render(
beforeAction = actionParser.beforeAction,
afterAction = actionParser.actions,
printActions = actionParser.printActions,
api = api,
checkActions = actionParser.checkActions,
purpose = purpose
)
try:
exec(case)
except Exception as e:
info["result"] = False
info["errorMsg"] = str(e)
info["messages"] = "\n".join([str(m) for m in session["result"]["messages"]]+session["result"]["failedChecks"]+session["result"]["successChecks"])
info["success"] = len(session["result"]["successChecks"])
info["failed"] = len(session["result"]["failedChecks"])
info["ok"] = False if session["result"]["failedChecks"] else True
elif purpose == "save":
case = ApiCase.query.filter_by(name=name).filter_by(userid=current_user.id).first()
if case:
info["result"] = False
info["errorMsg"] = "该名称的用例已存在"
else:
try:
case = ApiCase(name,desc,script,current_user.id)
db.session.add(case)
db.session.commit()
api.apicases.append(case)
db.session.add(api)
db.session.commit()
except Exception as e:
info["result"] = False
info["errorMsg"] = "数据库异常"
elif purpose == "edit":
print("edit case",name)
try:
caseid = int(request.form.get("caseid"))
case = ApiCase.query.filter_by(id=caseid).filter_by(userid=current_user.id).first()
if case:
case.name = name.strip()
case.desc = desc.strip()
case.content = script.strip()
db.session.add(case)
db.session.commit()
else:
info = {"result":False,"errorMsg":"该用例不存在或已被删除"}
except Exception as e:
info["result"] = False
info["errorMsg"] = "数据库异常"
else:
info = {"result":False,"errorMsg":"不支持的请求!"}
return jsonify(info)