坚持写博客来记录学习过程,哪怕学习的东西多么简单!下面是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. 日志统计 尺取法【蓝桥杯2018 C/C++ B组】

    标题:日志统计 小明维护着一个程序员论坛.现在他收集了一份"点赞"日志,日志共有N行.其中每一行的格式是: ts id 表示在ts时刻编号id的帖子收到一个"赞" ...

  2. First Steps: Command-line

    This brief tutorial will teach how to get up and running with the Flyway Command-line tool. It will ...

  3. How Flyway works

    The easiest scenario is when you point Flyway to an empty database. It will try to locate its schema ...

  4. P1494 [国家集训队]小Z的袜子(莫队算法)

    莫队板子 代码 #include <cstdio> #include <algorithm> #include <cstring> #include <cma ...

  5. Paper Reading: In Defense of the Triplet Loss for Person Re-Identification

    In Defense of the Triplet Loss for Person Re-Identification  2017-07-02  14:04:20   This blog comes ...

  6. 案例2:用一条SQL查询出数学语文成绩都大于80分的学生姓名?

    方法1: 查出科目成绩有小于80分的学生姓名,再约束并去重学生不等于查出来的姓名 select distinct A.name from t_score A where A.name not in(s ...

  7. 在WPF中调用另存为对话框

    Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog(); dlg.FileName = "User ...

  8. Android之使用传感器获取相应数据

    Android的大部分手机中都有传感器,传感器类型有方向.加速度(重力).光线.磁场.距离(临近性).温度等. 方向传感器:   Sensor.TYPE_ORIENTATION 加速度(重力)传感器: ...

  9. Pandas 基础(1) - 初识及安装 yupyter

    Hello, 大家好, 昨天说了我会再更新一个关于 Pandas 基础知识的教程, 这里就是啦......Pandas 被广泛应用于数据分析领域, 是一个很好的分析工具, 也是我们后面学习 machi ...

  10. Codeforces 510 E. Fox And Dinner

    题目链接:http://codeforces.com/problemset/problem/510/E 乍一看和那啥魔术球问题有点神似啊/XD 其实是不一样的. 解决这道问题的关键在于发现若是相邻的两 ...