[Twisted-web] Setting up a project.

Govind Salinas blix at sophiasuchtig.com
Tue Aug 5 19:30:23 EDT 2008


Hi Folks,

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.


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[1], 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

content-dir/
   __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 content-dir
   main.html -- The html files here are really the mako templates
   main.css
   etc...

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.

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 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.

[1] 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.

Thank You in Advance,
Govind



More information about the Twisted-web mailing list