0

I'm looking for a way to write a small python app (ubuntu) which will serve a simple webpage on port 80 for example but also will detect when someone load it (visits it). I want to raise a certain event upon visiting and execute another function which will send some information to an external device.

An yes, I'm new to python. I do have a script for just serving a page, but can't get a part into it to raise the event of visiting this page:

import tornado.ioloop
import tornado.web


class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.write("Hello, world")

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

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

Thank you for you help!)

p.s. In total it's a "physical" counter..so to say:) I have it all running on Raspberry Pi and want to light up leds upon visitors viewing the page.

4

1 回答 1

2

您是否尝试过以下简单的方法:

...
def get(self):
    self.write("Hello, world")
    light_the_leds()
...

您所要做的就是编写light_the_leds函数。light_the_leds还是您真正要问的是“我如何编写函数”?

于 2013-07-14T16:37:44.613 回答