Python Web简单加法器的实现--Python
坚持写博客来记录学习过程,哪怕学习的东西多么简单!下面是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的更多相关文章
- The Python web services developer: XML-RPC for Python
原文地址:http://www.ibm.com/developerworks/webservices/library/ws-pyth10/index.html 摘要:概括地说,您可以将 XML-RPC ...
- Python web 简单服务器的搭建与运行
搭建python的CGI环境: 假设在/var/www/cgi-bin下建立一个hello.py的文件 在ubuntu下打开终端 然后用命令 cd /var/www/ 进入后执行命令 : python ...
- [原]Python Web部署方式总结
不要让服务器裸奔 学过PHP的都了解,php的正式环境部署非常简单,改几个文件就OK,用FastCgi方式也是分分钟的事情.相比起来,Python在web应用上的部署就繁杂的多,主要是工具繁多,主流服 ...
- [转]Python Web部署方式总结
学过PHP的都了解,php的正式环境部署非常简单,改几个文件就OK,用FastCgi方式也是分分钟的事情.相比起来,Python在web应用上的部署就繁杂的多,主要是工具繁多,主流服务器支持不足,在了 ...
- Python Web部署方式全汇总
学过PHP的都了解,php的正式环境部署非常简单,改几个文件就OK,用FastCgi方式也是分分钟的事情.相比起来,Python在web应用上的部署就繁杂的多,主要是工具繁多,主流服务器支持不足. 在 ...
- 干货分享:Python Web 部署方式大全
不要让服务器裸奔 学过PHP的都了解,php的正式环境部署非常简单,改几个文件就OK,用FastCgi方式也是分分钟的事情.相比起来,Python在web应用上的部署就繁杂的多,主要是工具繁多,主流服 ...
- 通过uwsgi+nginx启动flask的python web程序
通过uwsgi+nginx启动flask的python web程序 一般我们启动python web程序的时候都是通过python直接启动主文件,测试的时候是可以的,当访问量大的时候就会出问题pyth ...
- 系列文章--Python Web编程
我从网上找到了其他园友的文章,很不错,留着自己学习学习. Python Web编程(一)Python Web编程(二)Python Web编程(三)Python Web编程(四)Python Web编 ...
- Linux06 /Python web项目部署
Linux06 /Python web项目部署 目录 Linux06 /Python web项目部署 1. 部署方式 2. 纯后端代码部署/CRM为例 1. 部署方式 2. crm项目详细部署步骤 3 ...
随机推荐
- 【Python045-魔法方法:属性访问】
一.属性的几种访问方式 1.类.属性名 >>> class C: def __init__(self): self.x = 'X-man' >>> c = C() ...
- QML获取随机颜色
rect.color =);//random返回0~1的随机数
- UML类图中箭头的含义
Explanation of the UML arrows Here's some explanations from the Visual Studio 2015 docs: UML Class D ...
- 【教程】Git在Eclipse中的安装和基本使用
一.安装 点击 Help->Install New Software->add 安装地址为:http://download.eclipse.org/egit/updates/ 选择插件 ...
- jvm:分析工具
bin/jvisualvm.exe 可查看类实例数 bin/jconsole.exe 监控线程,堆,等 http://blog.csdn.net/yaowj2/article/details/7107 ...
- Hadoop【单机安装-测试程序WordCount】
Hadoop程序说明,就是创建一个文本文件,然后统计这个文本文件中单词出现过多少次! (MapReduce 运行在本地 启动JVM ) 第一步 创建需要的文件目录,然后进入该文件中进行编辑 ...
- Leaflet中添加的不同图层样式图标
如上图,具体问题请查看对应html页引用的basemaps的css样式. 如下图是本项目引用的css样式: .basemap img { width: 48px; border: 2px solid ...
- Common-io,FileUtils工具类的使用
package Cristin.Common.File; import org.apache.commons.io.FileUtils; import org.apache.commons.io.fi ...
- 【Java】【事件处理机制】
import javax.swing.*;import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.Actio ...
- jsTree使用
引用:jsTreede css 与Js 初始化jsTree: //加载树 function initTree(treeData) { $.jstree.destroy(); $('#treeDiv') ...