Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Just add <code>wsgi_resource.putChild('media', File("/path/to/media"))</code> after the <code>wsgi_resource</code> assignment. You'll need to <code>from twisted.web.static import File</code> of course.</p> <p>Update 1:</p> <p>Turns out <a href="http://twistedmatrix.com/documents/11.0.0/api/twisted.web.wsgi.WSGIResource.html" rel="nofollow"><code>WSGIResource</code></a> rejects putChild() attempts. There's a solution here: <a href="http://blog.vrplumber.com/index.php?/archives/2426-Making-your-Twisted-resources-a-url-sub-tree-of-your-WSGI-resource....html" rel="nofollow">http://blog.vrplumber.com/index.php?/archives/2426-Making-your-Twisted-resources-a-url-sub-tree-of-your-WSGI-resource....html</a></p> <p>Update 2:</p> <p><strong>jungo.py</strong></p> <pre><code>from twisted.application import internet from twisted.web import resource, wsgi, static, server from twisted.python import threadpool from twisted.internet import reactor def wsgiApplication(environ, start_response): start_response('200 OK', [('Content-type', 'text/plain')]) return ['Hello, world!'] class SharedRoot(resource.Resource): """Root resource that combines the two sites/entry points""" WSGI = None def getChild(self, child, request): request.prepath.pop() request.postpath.insert(0, child) return self.WSGI def render(self, request): return self.WSGI.render(request) class JungoHttpService(internet.TCPServer): def __init__(self, port): self.__port = port pool = threadpool.ThreadPool() sharedRoot = SharedRoot() # substitute with your custom WSGIResource sharedRoot.WSGI = wsgi.WSGIResource(reactor, pool, wsgiApplication) sharedRoot.putChild('media', static.File("/path/to/media")) internet.TCPServer.__init__(self, port, server.Site(sharedRoot)) self.setName("WSGI/HttpJungo") self.pool = pool def startService(self): internet.TCPServer.startService(self) self.pool.start() def stopService(self): self.pool.stop() return internet.TCPServer.stopService(self) def getServerPort(self): """ returns the port number the server is listening on""" return self.__port </code></pre> <p><strong>jungo.tac</strong></p> <pre><code>from twisted.application import internet, service from jungo import JungoHttpService application = service.Application("jungo") jungoService = JungoHttpService(8080) jungoService.setServiceParent(application) </code></pre> <p><code>$ twistd -n -y jungo.tac</code></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload