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

Template.py:(模板引擎文件)

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

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 \n\n")
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())

Python Web简单加法器的实现--Python的更多相关文章

  1. The Python web services developer: XML-RPC for Python

    原文地址:http://www.ibm.com/developerworks/webservices/library/ws-pyth10/index.html 摘要:概括地说,您可以将 XML-RPC ...

  2. Python web 简单服务器的搭建与运行

    搭建python的CGI环境: 假设在/var/www/cgi-bin下建立一个hello.py的文件 在ubuntu下打开终端 然后用命令 cd /var/www/ 进入后执行命令 : python ...

  3. [原]Python Web部署方式总结

    不要让服务器裸奔 学过PHP的都了解,php的正式环境部署非常简单,改几个文件就OK,用FastCgi方式也是分分钟的事情.相比起来,Python在web应用上的部署就繁杂的多,主要是工具繁多,主流服 ...

  4. [转]Python Web部署方式总结

    学过PHP的都了解,php的正式环境部署非常简单,改几个文件就OK,用FastCgi方式也是分分钟的事情.相比起来,Python在web应用上的部署就繁杂的多,主要是工具繁多,主流服务器支持不足,在了 ...

  5. Python Web部署方式全汇总

    学过PHP的都了解,php的正式环境部署非常简单,改几个文件就OK,用FastCgi方式也是分分钟的事情.相比起来,Python在web应用上的部署就繁杂的多,主要是工具繁多,主流服务器支持不足. 在 ...

  6. 干货分享:Python Web 部署方式大全

    不要让服务器裸奔 学过PHP的都了解,php的正式环境部署非常简单,改几个文件就OK,用FastCgi方式也是分分钟的事情.相比起来,Python在web应用上的部署就繁杂的多,主要是工具繁多,主流服 ...

  7. 通过uwsgi+nginx启动flask的python web程序

    通过uwsgi+nginx启动flask的python web程序 一般我们启动python web程序的时候都是通过python直接启动主文件,测试的时候是可以的,当访问量大的时候就会出问题pyth ...

  8. 系列文章--Python Web编程

    我从网上找到了其他园友的文章,很不错,留着自己学习学习. Python Web编程(一)Python Web编程(二)Python Web编程(三)Python Web编程(四)Python Web编 ...

  9. Linux06 /Python web项目部署

    Linux06 /Python web项目部署 目录 Linux06 /Python web项目部署 1. 部署方式 2. 纯后端代码部署/CRM为例 1. 部署方式 2. crm项目详细部署步骤 3 ...

随机推荐

  1. android 系统 不深度休眠【转】

    本文转载自:https://blog.csdn.net/fmc088/article/details/80401405 1.分析解析 android系统有earlysuspend和suspend两种休 ...

  2. POJ 2387 Til the Cows Come Home 【最短路SPFA】

    Til the Cows Come Home Description Bessie is out in the field and wants to get back to the barn to g ...

  3. The more... the more句型

    百度文库:https://wenku.baidu.com/view/a7f1067f59fb770bf78a6529647d27284a73374b.html the more ... , the m ...

  4. 【OData】使用Odata获取数据之后再次获取可能得不到最新的数据问题记录

    工作上遇到个问题是关于系统后台数据库更新了某数据后, 前台界面刷新显示的不是最新的数据.但是大约10分后再次刷新就能显示新的数据,或者重启IIS等web server host. 最开始认为可能是因为 ...

  5. Codeforces-Anastasia and pebbles

    这是一道很有意思的(水)题. 地址戳:http://codeforces.com/problemset/problem/789/A 题目的大意呢,就是一个可爱的大姐姐的故事.说是啊,她每天都带着两个一 ...

  6. Latex: 设置 threeparttable footnote 行宽度

    参考: Table width with threeparttable smaller than notes and caption? Latex: 设置 threeparttable footnot ...

  7. JS计算前一天或后一天,前一月后一月

    JS计算前一天或后一天,前一月后一月,上一天下一下,上一月下一月. 方法一: function ktkGetNextMonth(currentDate, scaleStep) { //scaleSte ...

  8. Jquery Validate 相关参数

    Jquery Validate 相关参数 //定义中文消息 var cnmsg = { required: “必选字段”, remote: “请修正该字段”, email: “请输入正确格式的电子邮件 ...

  9. el-cascader 级联选择器使用时遇到的一些问题

    Element UI Cascader官网文档 <el-form-item label="章节" style="margin-right: 64px"&g ...

  10. jqGrid API (转)

    来源:https://www.cnblogs.com/MonaSong/p/5109991.html JQGrid是一个在jquery基础上做的一个表格控件,以ajax的方式和服务器端通信. JQGr ...