2017-06-20 65 views
0

我有新鮮的Django項目沒有任何應用程序只是默認設置(如管理員)扭曲的Web服務的Django項目

我的計劃是有視頻聊天和我的Django項目內即時通訊

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() 

我跑MY_DJANGO_PROJECT_PATH中我扭曲的Web服務器和端口8080

cd MY_DJANGO_PROJECT_PATH twistd -n web --wsgi=MY_DJANG_PROJECT

當我開到瀏覽器服務器啓動(http://127.0.0.1:8080/),我得到了一個錯誤

WSGI應用程序錯誤

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

沒有人幫助我?提前致謝。

+0

你能解釋一下爲什麼要使用雙絞線服務器來運行Django的例子? –

+0

我想使用Django進行我的Twisted應用程序的身份驗證。 –

回答

0

我已經能夠在twisted中使用我的Django項目,使用twisted.web.wsgi.WSGIResource。

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)