Created
June 16, 2011 18:30
-
-
Save pilt/1029886 to your computer and use it in GitHub Desktop.
Django management command for running a Tornado server
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
# coding=utf-8 | |
from django.core.management.base import BaseCommand, CommandError | |
from django.conf import settings | |
import tornado.ioloop | |
import tornado.web | |
class MainHandler(tornado.web.RequestHandler): | |
def get(self): | |
self.write("Tornado says hello!") | |
tornado_settings = { | |
"cookie_secret": settings.SECRET_KEY, | |
"static_path": settings.TORNADO_SERVE_ROOT, | |
"static_url_prefix": settings.TORNADO_SERVE_PATH, | |
} | |
application = tornado.web.Application([ | |
(r"/", MainHandler), | |
], **tornado_settings) | |
class Command(BaseCommand): | |
help = 'Run a tornado server.' | |
def handle(self, *args, **options): | |
application.listen(settings.TORNADO_PORT) | |
tornado.ioloop.IOLoop.instance().start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment