zoukankan      html  css  js  c++  java
  • Python Web简单加法器的实现--Python

    坚持写博客来记录学习过程,哪怕学习的东西多么简单!下面是python中cgi相关知识。

    Template.py(模板引擎文件)

    #模板引擎
    def start_response(resp="text/html"):
      return 'Content-type: '+resp+ ' '

    def start_form(the_url="",form_type="POST"):
      return '<form action="'+the_url+'"method="'+form_type+'">'

    def end_form(submit_msg="求和"):
      return '<input type="submit" value="' +submit_msg+'">'

    def input_label(name,placeholder="",value="",readonly=None):
    if readonly is None:
      return '<input type="text" size="20" value="'+value+'" name="'+name+'" placeholder="'+placeholder+'">'
    else:
      return '<input type="text" size="20" value="'+value+'" readonly="'+readonly+'" name="'+name+'" placeholder="'+placeholder+'">'

    def context(word):
    return word

    def start_div(align,style):
      return '<div align="'+align+'"style="'+style+'">'
    def end_div():
      return "</div>"
    def img(src):
      return '<img src="'+src+'">

    main.py

    import cgitb,cgi
    from Template import *
    form1=cgi.FieldStorage()
    num1=form1.getvalue("Num1")
    num2=form1.getvalue("Num2")
    num3=None
    if not num1 is None and not num2 is None:
      num1=int(num1)
      num2=int(num2)
      num3=num1+num2
    # print("Content-type:text/html ")
    print(start_response())
    # print(img("../views/add.png"))
    # print(start_div("center","margin-top:40px;"))
    # print(img("../views/add.png"))
    # print(end_div())
    print(start_div("center","margin:50px 0 0 0"))
    print(start_form())
    print(input_label("Num1","参数1"))
    print("+")
    print(input_label("Num2","参数2"))
    print("=")
    if num3 is None:
      print(input_label("Num3","结果","","readonly"))
    else:
    print(input_label("Num3", "结果",str(num3), "readonly"))
    print(end_form())
    print(end_div())

  • 相关阅读:
    Working with Deployment Configurations in CodeDeploy
    ECS 容器实例生命周期
    设置 API Gateway 金丝雀版本部署
    Elastic Beanstalk 滚动环境配置更新
    Kinesis Data Firehose 中的数据保护
    为 API Gateway REST API 资源启用 CORS
    高级 AWS Elastic Beanstalk 环境配置
    Amazon SWF Actors
    AWS CloudFormation 模板结构
    字符编码
  • 原文地址:https://www.cnblogs.com/qikeyishu/p/8544687.html
Copyright © 2011-2022 走看看