如何将Django应用程序合并到现有的扭曲服务器中? [英] How does one incorporate a Django application into an existing twisted server?

查看:44
本文介绍了如何将Django应用程序合并到现有的扭曲服务器中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在向现有的双绞线服务器添加/提供一个复杂的Django应用程序(现有的双绞线服务器不提供任何http服务,至少在标准端口上不提供此服务),因此我可以使用端口80工作).

I'm looking to add/serve a complicated django application, to an existing twisted server (the existing twisted server doesn't serve any http services, at least not on the standard ports, so I can use port 80 for this work).

到目前为止,我可以找到的所有示例都是针对Twisted的早期版本的,似乎无法使用最新版本进行操作.

All of the examples I can find to date are for earlier versions of twisted, and do not seem to work, out of the box, with the latest version.

在哪里可以找到最新的教程,示例集或配方,以显示通过最新版的Twisted为复杂的Django应用程序提供服务的正确接线方式?

Where can I find an up to date tutorial, set of examples or recipe, showing the correct wiring for serving a complex Django application through the latest version of twisted?

更具体地说,我已经接近了这个小问题:

More specifically, I have gotten close with this little blurb:

from twisted.web.resource import Resource
from twisted.web import wsgi
from twisted.internet import reactor
from django.core.handlers.wsgi import WSGIHandler
os.environ['DJANGO_SETTINGS_MODULE'] = 'app.settings'
django_application = WSGIHandler()
django_resource = wsgi.WSGIResource(reactor, reactor.getThreadPool(), django_application)

root = Resource()
root.putChild("",django_resource)
from twisted.application import service
application = service.Application("app")

internet.TCPServer(8080, Site(root)).setServiceParent(application)

(它将提供django项目的基本内容,但似乎无法正确提供我的静态内容,并且似乎不会自动处理项目中子目录中提供的django应用程序)

(it will serve the basic contents of my django project, but seems to fail to properly serve my static content, and doesn't seem to automatically handle django applications served at subdirectories within my project)

推荐答案

发现我的错误:

# All this work is un-necessary overkill
#root = Resource()
#root.putChild("",django_resource)
#from twisted.application import service
#application = service.Application("app")

internet.TCPServer(8080, Site(django_resource)).setServiceParent(application)

这篇关于如何将Django应用程序合并到现有的扭曲服务器中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆