Am trying to integrate Django app with Tornado for some asynchronous request handling (chat). (Reference - https://github.com/thejsj/django-and-rethinkdb)
For that reason, I integrated but couldn't run the tornado_main.py after initiating the Django app in windows (command prompt as admin).
when I run
>c:\python27\python tornado_main.py
It throws below error
I tried changing different django versions and tried the code as suggested in How use Django with Tornado web server?
Am not sure what is wrong with the configurations that were missing.
Here is my tornado_main.py code-
import django.core.handlers.wsgi
from django.conf import settings
import os
from tornado.options import options, define, parse_command_line
import tornado.httpserver
import tornado.ioloop
import tornado.web
import tornado.wsgi
import tornado.websocket
import tornado.gen
from change_feed import print_changes, SocketHandler, MessageHandler
django.setup()
def main():
os.environ['DJANGO_SETTINGS_MODULE'] = 'app.settings'
wsgi_app = tornado.wsgi.WSGIContainer(
django.core.handlers.wsgi.WSGIHandler()
)
current_dir = os.path.dirname(os.path.abspath(__file__))
static_folder = os.path.join(current_dir, 'static')
tornado_app = tornado.web.Application([
('/new-messages/', SocketHandler),
('/messages/', MessageHandler),
(r'/static/(.*)', tornado.web.StaticFileHandler, { 'path': static_folder }),
('.*', tornado.web.FallbackHandler, dict(fallback=wsgi_app)),
])
server = tornado.httpserver.HTTPServer(tornado_app)
server.listen(8000)
tornado.ioloop.IOLoop.current().add_callback(print_changes)
tornado.ioloop.IOLoop.instance().start()
if __name__ == '__main__':
main()
Am using django 1.8.1 Python 3.4
Could you please suggest how to run this server on windows ?
Here is Settings.py
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '=1gnq3++4*3to$cun@-(f86j_4f^!-k96#f%eej3k$be1o^17o'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'app'
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
)
ROOT_URLCONF = 'testTornado.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'testTornado.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
DATABASES = {
'default': {
'NAME': 'tornadotest',
'ENGINE': 'django.db.backends.mysql',
'USER': 'root',
'PASSWORD': 'dhyana007',
}
}
# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/
STATIC_URL = '/static/'
LOGGING_CONFIG=None