On Jun 19, 2013, at 7:28 PM, Jo as Queeniebee wrote:

> Alright, then I'll use Twisted's built-in! But I still have my same question: 
> Should I write a separate file containing all the resources and another file 
> with the server? To deploy a content server on the RPi, do I need to wrap all 
> the files within a .tac file?
> 
> Joelle
> 

This is highly dependent upon your application.  Maybe you can contain 
everything you need to do in a single .py file and run it. Or maybe it would be 
beneficial to use separate modules or packages. These aren't really 
twisted-specific concerns. It's a matter of laying out your application so you 
can import the code you need, where you need it. If you have all of your 
Resources in a separate module or package, then you need to figure out how to 
import those and hook them up to the Site object.

Extending the simple example from earlier, you might have a "run.py" in your 
app:

## myapp/run.py
#
from twisted.web import server
from twisted.internet import reactor

from myapp.views import MyResource

site = server.Site(MyResource())
reactor.listenTCP(8080, site)
reactor.run()

This is highly simplified, but hopefully you can see it's just basic python. 
twisted.web.server.Site needs a Resource, so you have to figure out how to 
supply it. Could be in the same file, or could be importable from some other 
package or module. In this case, we've decided that we'll have a views module 
that contains MyResource.


A .tac file is one way to handle application startup. You could also create a 
twistd plugin: https://twistedmatrix.com/documents/current/core/howto/tap.html. 
Or you could have a plain old python file with reactor.run() in it. This is 
prevalent in many of the howto examples and what the example above shows. I 
wouldn't really worry about .tac or plugins for the time being.


At any rate, we're venturing into different territory now. You'll need to share 
some code (http://sscce.org/) or give a more complete description of what 
you're trying to do in order to get practical advice. It would be better to 
start a new thread with a clear intent and a different subject line, unless you 
still have questions about using jinja2.


Lucas
_______________________________________________
Twisted-web mailing list
[email protected]
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web

Reply via email to