Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How use Django with Tornado web server?

How do I use Django with the Tornado web server?

like image 578
xRobot Avatar asked Mar 28 '10 21:03

xRobot


People also ask

Which web server is used by Django?

Django's primary deployment platform is WSGI, the Python standard for web servers and applications. Django's startproject management command sets up a minimal default WSGI configuration for you, which you can tweak as needed for your project, and direct any WSGI-compliant application server to use.

Does Django have a built in webserver?

Using Django's built in web server in a production environment - Stack Overflow. Stack Overflow for Teams – Start collaborating and sharing organizational knowledge.

How do I run a tornado web server?

If you want to daemonize tornado - use supervisord. If you want to access tornado on address like http://mylocal.dev/ - you should look at nginx and use it like reverse proxy. And on specific port it can be binded like in Lafada's answer.


1 Answers

it's very simple ( especially with django 1.4) .

1 - just build your django project( and apps ) and make sure it works fine.

2- create a new python file at the root folder ( same dir where you used django-admin.py startproject)

3- then copy the code below , edit the os.environ['DJANGO_SETTINGS_MODULE'] line, and paste it in that new .py file.

import os import tornado.httpserver import tornado.ioloop import tornado.wsgi import sys import django.core.handlers.wsgi #sys.path.append('/home/lawgon/') # path to your project ( if you have it in another dir).   def main():     os.environ['DJANGO_SETTINGS_MODULE'] = 'myProject.settings' # path to your settings module     application = django.core.handlers.wsgi.WSGIHandler()     container = tornado.wsgi.WSGIContainer(application)     http_server = tornado.httpserver.HTTPServer(container)     http_server.listen(8888)     tornado.ioloop.IOLoop.instance().start()  if __name__ == "__main__":     main() 

Django 1.6+ it should be like this:

import os import tornado.httpserver import tornado.ioloop import tornado.wsgi from django.core.wsgi import get_wsgi_application  def main():     os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings' # path to your settings module     application = get_wsgi_application()     container = tornado.wsgi.WSGIContainer(application)     http_server = tornado.httpserver.HTTPServer(container)     http_server.listen(8888)     tornado.ioloop.IOLoop.instance().start()  if __name__ == "__main__":     main() 
like image 50
Moayyad Yaghi Avatar answered Sep 16 '22 15:09

Moayyad Yaghi