Created
March 8, 2010 08:53
-
-
Save rmax/325000 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tornado.httpserver | |
import tornado.ioloop | |
import tornado.options | |
import tornado.web | |
import tornado.wsgi | |
from tornado.options import define, options | |
define("port", default=8888, help="run on the given port", type=int) | |
def simple_app(environ, start_response): | |
status = "200 OK" | |
response_headers = [("Content-Type", "text/plain")] | |
start_response(status, response_headers) | |
return ["wsgi path_info: %s" % environ["PATH_INFO"]] | |
class TestHandler(tornado.web.RequestHandler): | |
def get(self, param): | |
self.write("request path: %s" % param) | |
class MainHandler(tornado.web.RequestHandler): | |
def get(self): | |
self.set_header("Content-Type", "text/html") | |
self.write('<a href="/test/hello test">hello test</a><br>' | |
'<a href="/wsgi/hello wsgi">hello wsgi</a>') | |
def main(): | |
tornado.options.parse_command_line() | |
wsgi_app = tornado.wsgi.WSGIContainer(simple_app) | |
application = tornado.web.Application([ | |
(r"/", MainHandler), | |
(r"/test/(.*)", TestHandler), | |
(r".*", tornado.web.FallbackHandler, dict(fallback=wsgi_app)), | |
]) | |
http_server = tornado.httpserver.HTTPServer(application) | |
http_server.listen(options.port) | |
tornado.ioloop.IOLoop.instance().start() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment