python抽奖与页面显示_CGI 简单的python显示的页面

简介

python 进行服务器的页面的显示 cgi common gateway interface 公用网关接口

简单操作

python3 -m http.server --cgi 8001

新建一个cgi-bin目录

里面存入一个 py文件

#!/usr/bin/env python

#coding=utf-8

import cgi

header = 'Content-Type: text/html\n\n'

formhtml = '''

Friends CGI Demo

Friends list for: NEW USER

Enter your Name:

How many friends do you have?

%s

'''

fradio = ' %s\n'

def showForm():

friends = ''

for i in [0, 10, 25, 50, 100]:

checked = ''

if i == 0:

checked = 'CHECKED'

friends = friends + fradio % \

(str(i), checked, str(i))

print header + formhtml % (friends)

reshtml = '''

Friends CGI Demo

Friends list for:%s

Your name is: %s

You have %s friends.

'''

def doResults(who, howmany):

print header + reshtml %(who, who, howmany)

def process():

form = cgi.FieldStorage()

if form.has_key('person'):

who = form['person'].value

else:

who = 'NEW USER'

if form.has_key('howmany'):

howmany = form['howmany'].value

else:

howmany = 0

if form.has_key('action'):

doResults(who, howmany)

else:

showForm()

if __name__ == '__main__':

process()

访问 http://localhost:8001/cgi-bin/cgii.py

参考链接

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值