2017-06-20 7 views
0

Ich habe frisches Django-Projekt ohne jede Anwendung nur die Standardeinstellungen (zum Beispiel admin)Verdrehte Webserving Django Projekt

Mein Plan Video-Chat und Instant Messaging in meinem Django-Projekt haben.

wsgi.py

import os, sys 
from django.core.wsgi import get_wsgi_application 

sys.path.append('MY_DJANGO_PROJECT_PATH') 
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "MY_DJANGO_PROJECT.settings") 
application = get_wsgi_application() 

Ich betreibe meine Verdrehte Web-Server innerhalb MY_DJANGO_PROJECT_PATH und starten Sie den Server auf Port 8080.

cd MY_DJANGO_PROJECT_PATH twistd -n web --wsgi=MY_DJANG_PROJECT

Als ich sie an den Browser öffnen (http://127.0.0.1:8080/), ich habe einen Fehler

erhalten Anwendung

WSGI Fehler

File "/Library/Python/2.7/site-packages/Twisted-15.5.0-py2.7-macosx-10.12-intel.egg/twisted/web/wsgi.py", line 315, in run appIterator = self.application(self.environ, self.startResponse) exceptions.TypeError: 'module' object is not callable

Hilft mir jemand mit diesem? Danke im Voraus.

+0

Können Sie erklären, warum Sie Django mit dem Twisted-Server ausgeführt werden soll? –

+0

Ich möchte Django zur Authentifizierung für meine Twisted-Anwendung verwenden. –

Antwort

0

Ich konnte mein Django-Projekt innerhalb der Twisted mit twisted.web.wsgi.WSGIResource dienen.

Beispiel folgend here.

my_django_project.tac

from twisted.web import server 
from twisted.web.wsgi import WSGIResource 
from twisted.python.threadpool import ThreadPool 
from twisted.internet import reactor 
from twisted.application import service, strports 

# Create and start a thread pool 
wsgiThreadPool = ThreadPool() 
wsgiThreadPool.start() 

# ensuring that it will be stopped when the reactor shuts down 
reactor.addSystemEventTrigger('after', 'shutdown', wsgiThreadPool.stop) 

import sys 
sys.path.append('MY_DJANGO_PROJECT_PATH') 
from MY_DJANGO_PROJECT import wsgi 

# Create the WSGI resource 
wsgiAppAsResource = WSGIResource(reactor, wsgiThreadPool, 
wsgi.application) 

# Hooks for twisted 
application = service.Application('My Django Project') 
server = strports.service('tcp:8080', server.Site(wsgiAppAsResource)) 
server.setServiceParent(application)