zoukankan      html  css  js  c++  java
  • 问题反馈小平台实现 ----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服务

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




  • 相关阅读:
    1月6日 作业 穷举
    1.4 作业
    12月31日 作业
    12月29日-练习成果
    12月30日作业-<转>字符集编码
    1.22作业
    集合
    泛型
    CPU接口练习 (仅以此程序证明 某个同学真的有毒!有毒!!!)
    继承知识点总结
  • 原文地址:https://www.cnblogs.com/hmysql/p/9134874.html
Copyright © 2011-2022 走看看