• 问题反馈小平台实现 ----python练习


    python版本python3.6.1

    import tornado.ioloop
    import tornado.web
    import datetime
    #!gbk

    class MainHandler(tornado.web.RequestHandler):
    def get(self):
    print('get')
    u = self.get_argument('user')
    p = self.get_argument('pwd')
    if u == 'admin' and p == '123':
    self.write('登陆成功!')
    else:self.write('登陆失败!')

    def post(self, *args, **kwargs):

    u = self.get_argument('user')
    pr = self.get_argument('depa')
    p = self.get_argument('problem')
    fh = open('hgr', 'a+')
    fh.write(datetime.datetime.now().strftime('%Y.%m.%d-%H:%M:%S')+' ')
    fh.write(u+' ')
    fh.write(pr+' ')
    fh.write(p+' ')
    fh.close()
    print(datetime.datetime.now().strftime('%Y.%m.%d-%H:%M:%S'),u,pr,p)
    self.write('提交成功!请等待稍后处理问题。(^_^)')

    application = tornado.web.Application([
    (r"/index", MainHandler),
    ])

    if __name__ == "__main__":
    application.listen(8888)
    tornado.ioloop.IOLoop.instance().start()

    运行上面的代码 后 把以下html代码 放httpd /var/www/html/中


    index.html


    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8" method="GET">
    <title>Title</title>
    </head>
    <body>
    <form action="http://192.168.1.62:8888/index" method="POST">
    姓名:<input type="text" name="user"/>
    部门:<input type="text" name="depa"/>
    问题描述:<input type="text" name="problem"/>
    <input type="submit" value="提交" />
    </form>
    </body>
    </html>
    注:192.168.1.62:8888 python运行的IP和端口

    运行httpd服务

    可以 看到程序打印出日志,且文件中也有写入数据。




  • 相关阅读:
    luogu2394 yyy loves Chemistry I
    luogu2393 yyy loves Maths II
    2018年01月刷题学习日记
    luogu2590 [ZJOI2008]树的统计
    HDU 2087 剪花布条
    HDU 1686 Oulippo
    HDU 1711 Number Sequence(KMP模板)
    HDU 3336 Count the String(KMP+DP)
    UVa 1614 奇怪的股市
    UVa 12174 Shuffle(滑动窗口)
  • 原文地址:https://www.cnblogs.com/hmysql/p/9134874.html
Copyright © 2020-2023  润新知