當前位置: 首頁>>代碼示例>>Python>>正文


Python Template.content方法代碼示例

本文整理匯總了Python中jinja2.Template.content方法的典型用法代碼示例。如果您正苦於以下問題:Python Template.content方法的具體用法?Python Template.content怎麽用?Python Template.content使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在jinja2.Template的用法示例。


在下文中一共展示了Template.content方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: sendcaserequest

# 需要導入模塊: from jinja2 import Template [as 別名]
# 或者: from jinja2.Template import content [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)
開發者ID:zippies,項目名稱:ApiPlatform,代碼行數:75,代碼來源:caseView.py


注:本文中的jinja2.Template.content方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。