import web import webbrowser urls = ('/' ,'Index' , '/upload', 'Upload') class Upload: def GET(self): return """<html><head><title>web.py test</title></head><body> <form method="POST" action="" enctype="multipart/form-data" > username:<input type="text" name="un" value=""/> passwd:<input type="password" name="pwd" value=""/> <select name="adserver_id" id="adserver_id" multiple=""> <option value="1">Coretest2 - 1</option> <option value="2">Coretest3 - 1</option> <option value="3">Coretest4 - 1</option> <option value="4">Coretest2 - 2</option> <option value="5">Coretest3 - 2</option> <option value="6">Coretest4 - 2</option> </select> <input type="submit" value="submit"/> </form> </body></html>""" #<input type="file" name="myfile" /> #上传文件 def POST(self): '''上传文件 x = web.input(myfile={}) return "filename: %s\n value: \n%s" % (x['myfile'].filename, x['myfile'].value) ''' x = web.input() data = u'<h1>user name:%s <br>password:%s <br>adserver_id:%s</h1>' % (x.un,x.pwd,x.adserver_id) return data.encode('gbk') class Index(): def GET(self): print '='*60 return u"""<html><head><title>web.py test</title></head><body> <h1 align="center"><a href="/upload">上传(POST)</a></h1> </html> """.encode('gbk') if __name__ == "__main__": webbrowser.open('http://127.0.0.1:8080') app = web.application(urls, globals(),True) app.run()