[Twisted-web] Setting up a project.
p.mayers at imperial.ac.uk
Wed Aug 6 05:27:31 EDT 2008
On Tue, Aug 05, 2008 at 06:30:23PM -0500, Govind Salinas wrote:
>I am trying to set up an application that uses twisted.web for doing
>some ad-hoc serving of data. If you are familiar with mercurial, what
>i am doing is very similar to the "hg serve" command except it is for
>use with git.
>So my question is, how should I compose the project. The how-tos and
>examples left me not sure of what I should do. I have something that
>runs and can serve up mako templates, but that is all it can do since
>I am doing everything manually. I would prefer not to have to code in
>serving things like css pages, 404 pages etc. I am sure this is
>already in twisted.web somewhere.
You haven't really given enough information.
I presume you're using twisted.web "Resource" classes and http server?
>Let me give you some information about the set up I have . Basically
>I have a python program running somewhere. I will have a default set
>of files that serve the content a particular way. The default set
>will contain mako templates, style sheets and perhaps some images.
>So I need a way to kick off the mako templates based on the URL. The
>templates may include each other.
>Here is the layout
> __config__.py -- This is a file that currently just sets up the mapping
> between a regex that selects a page and a path to
> where that page's template is under the
> main.html -- The html files here are really the mako templates
>My server class takes in a template dir, loads the config and starts a
>server. When it gets a request it matches it against the regexes and
>runs the template. There should be some initialization that sets up
>objects that get passed to the template (in addition to values from
>the regex parsing). This is all pretty brain-dead code.
Why does it need to be anything more than that? What's wrong with the
>I was hoping for some guidance on a better strategy for doing this.
>Any help would be appreciated. Bonus points if it is something that
>could easily be re-used on another webserver if someone wanted to host
>this on an existing website.
I don't understand that bit.
>I tried to post this before signing up to the list and I was rejected. I don't
>know if you guys consider that a problem.
> I am only using mako because it seems to suit my needs from a
>templating perspective. If there is something built into twisted
>that will do the job as well, then that would be one less dependency
>that I have.
You probably want to look at the Nevow toolkit which contains:
* A slightly better application server / resource object hierarhcy on
top of twisted.web - my understanding is this will eventually be
backported into twisted.web
* An XHTML & native-python deferred-aware templating engine
* An AJAX/COMET server called Athena
A little more detail about what's wrong with the current system would be
More information about the Twisted-web