Web Framework Reviews

Discussion in 'Python' started by istvan.albert, Jul 19, 2005.

  1. istvan.albert, Jul 19, 2005
    1. Advertisements

  2. You've never used Nevow, have you?
    Comparing it to Cheetah or ZPT means that you never used it.

    Nevow is exactly what you define as a web framework, and it would be
    quite interesting to know why you didn't put it in that section.
    Valentino Volonghi aka Dialtone, Jul 19, 2005
    1. Advertisements

  3. I have not used Nevow but I have seen a few examples of how it works
    and I kept track of it over the years.

    It used to be very similar to how Cheetah or ZPT does its job. You had
    a template, and you filled it with data to produce an output. It seems
    that it has now more features such a form submission and validation.

    On the other hand I even in its current form I don't see how I would to
    the simple things that I need every day. Create a session, set a
    cookie, redirect to another url, perform HTTP autentication, create
    filter, use another templating language? This is also integral part of
    the functionality that I expect from an web framework. Web specific
    things exposed in some python ic way.

    To avoid any negative feelings I'll remove all remarks to what I think
    is not a web framework.

    istvan.albert, Jul 19, 2005
  4. Formless has been part of nevow since the very beginning. It has also
    been part of woven (Nevow predecessor), just like liveevil (now enhanced
    and called livepage).

    The only part of nevow that you can compare to ZPT or Cheetah is its
    xmlfile template language. There is no way you can run Nevow on top of
    any other framework.

    Also you don't pass data to the templating engine. It's nevow that
    parses the template and iterates over it to render the page. The
    template is very stupid in nevow and everything is done in
    nevow.flat.flattenFactory called by nevow.rend.Page.
    Sessions are handled by default with twisted.web:

    from twisted.application import service, strports
    from nevow import appserver

    from nevow import rend, loaders, tags as t, inevow

    class RootPage(rend.Page):
    addSlash = True
    def display_session(self, ctx, data):
    return inevow.ISession(ctx).uid

    docFactory = loaders.stan(
    t.html[t.head[t.title["Session example"]],

    application = service.Application('Foobar')
    site = appserver.NevowSite(RootPage())
    server = strports.service('8080', site)

    Save this in a .py or .tac and run it with twistd -noy filename.tac/.py
    and open http://localhost:8080/ in your browser to see your session uid.

    If you want autentication:
    There are 2 examples (in the standard nevow distribution) that show how
    to handle authentication in an application transparent way (you don't
    have to touch your application by any means to add user authentication,
    which means you can write everything without taking care of this aspect
    of the app and then add it later).

    To redirect to another url just call IRequest(ctx).redirect(newurl)
    before the rendering begins (like in rend.Page.beforeRender) or in

    HTTPAuthentication is easily handled:
    just use that class as a base class for your blocked page.
    (this example is part of the standard nevow distribution).

    Nevow doesn't have filters because they are handled by twisted.web or
    twisted.web2 (which is, hopefully soon, going to be one of the required
    webservers to run nevow, the others are lighttpd, apache, any WSGI
    application server, nevow was in fact the first framework to support
    WSGI servers).

    If you want to use a different templating language you just need to
    write a custom loader. Somebody did this in the past (I don't recall the
    url of the project) that used cheetah-like templates.

    Then for the last point:
    you can expose directories or files using

    exposed objects are:
    those set as a value in rend.Page.children dict, you can reach them with
    an url like:
    Or assign an object to a child_foobar attribute like:

    p = rend.Page()
    p.child_foobar = static.File('/etc/')

    Or return an object from a child_foobar method.

    Or override rend.Page.childFactory(self, ctx, segment) to return an
    object in a dynamic way depending on the value of the segment argument.

    It seems to me that you really never tracked Nevow, your information is
    very incomplete. I think you should complete it before talking about
    Nevow :).
    Valentino Volonghi aka Dialtone, Jul 19, 2005
  5. istvan.albert

    Dave Cook Guest

    Take a look at the Nevow FAQ and examples. Also, Nevow sits on top of
    Twisted, so you have all of Twisted's features available.


    Dave Cook
    Dave Cook, Jul 19, 2005
  6. It seems to me that you really never tracked Nevow, your information is
    I think you should take what you posted above and put it up on your
    main site, because right now there is no way to find any information
    like this. Your entire intro is about templating and leaves one with
    no clues as to what else is there.

    One remark regarding stan. For me it is inconceivable that one would
    build (and debug) any complicated webpage as stan does it, one element
    at a time:

    docFactory = loaders.stan(
    t.html[t.head[t.title["Session example"]],

    The pages that I have to build invariably contain multiple nested html
    tables etc. I shudder to think that I would ever have to build them
    like that. I know you have an "inverse" ZPT like templates those are a
    lot friendlier on the eyes. For someone who is does not know what Nevow
    is seeing an example of Stan is very scary because IMO it does not
    scale at all. This again is just an opinion.

    Thanks for the explanations.

    istvan.albert, Jul 19, 2005
  7. Right now there are at least 2 web sites:
    http://divmod.org/users/exarkun/nevow-api/ + file inevow.py in nevow.

    And a new one:
    http://dictator.kieranholland.com/prose/Meet Stan.html

    And the page I linked in my previous post:
    this is a living site with the living examples distributed with nevow.
    at least one example of formless does not work right now because of
    changes that we are doing in trunk right now (only formless has some
    problems, all the others work pretty well).

    There are really a lot of examples, and you can learn a lot of stuff
    from them. More documentation will be useful for sure, but by just
    coming in the irc channel #twisted.web on freenode you would have
    obtained all the answers you wanted to write a better review paper :).
    I have a little project, developed during my little free time that is
    linked in my signature (weever). It has over 2000 lines of xhtml
    templates and you can see a living example here:

    I can guarantee you that when templates begin to be a bit too complex
    stan is what saves the day. I usually use xhtml for everything (and
    nevow has the best templating engine out there thanks to its flexibility
    and simplicity, there are only 3 special tags and 3 attributes, and we
    are working to make it even easier than that) but when xhtml gets
    complicated stan is incredibly useful.

    Anyway stan is also incredibly useful to write little examples without
    requiring a new xhtml file (ok... you may use loaders.xmlstr but...)

    And it does scale well anyway (Quotient is entirely built using stan and
    it's very big).
    Templating engines like ZPT prefer to put some code in the template,
    Nevow prefers to put code in python and allow you to write some xhtml in
    python too. python is easier to manage and less likely to be screwed by
    any designer that doesn't know what python is.
    np :)
    Valentino Volonghi aka Dialtone, Jul 19, 2005
  8. istvan.albert

    John Ziniti Guest

    From the web-page:

    Zope - Generation Z


    Weakness: Not pythonic. In fact you can barely use python with it!
    Ad-hoc lookup rules, competing standards DHTML vs ZPT. Can only be used
    with these two! The Z shaped thingy.


    "barely use python with it" and "can only be used with these two" are
    not entirely true. Zope development can be done in a through-the-web
    (TTW) fashion or via filesystem products. When developing TTW, it
    is true that you are somewhat limited in the amount of Python that
    you will be able to use.

    When you graduate to filesystem products, though, Zope becomes more of
    a set of APIs and a persistence layer for your objects and methods
    that are coded entirely in Python, with very little DTML (not DHTML)
    and ZPTs. IMHO, this is when Zope development becomes powerful.

    Maybe this is the Z-shaped learning curve you speak of: it takes a
    while developing in Zope to even know what all of the options are!

    John Ziniti, Jul 19, 2005
  9. istvan.albert

    Josef Meile Guest

    "barely use python with it" and "can only be used with these two" are
    I just want to add that ZPT and DTML are only intended for the
    presentation and not for the logic, which can be done all using python.
    However, as you may see, there are some zope developers that use it
    wrong and do lots of logic stuff within dtml or zpt.

    Josef Meile, Jul 19, 2005
  10. istvan.albert

    Tim Parkin Guest

    Firstly, I don't know of anyone who has built whole sites out of stan
    (it's not what it was created for). Although if built in a modular
    fashion I don't see why this would have problems 'scaling' or would be
    more difficult to visualise than a the equivalent tag soup html.

    Also it depends on what you mean by scale. We built a site for one of
    the biggest rugby sites in the world (over 300 requests per second).
    This uses a combination of stan and xhtml templates. Before we rebuilt
    the site using CSS layout (which you really should be looking at using
    to avoid the multiple nested tables you mention - which I presume are
    layout related) we were using client supplied html which was nested more
    than 10 levels deep.

    Most of this we were able to leave in the html and allow the client to
    manage via ftp. The bits that were dynamic were 'templated up' by
    putting slots and renderers. Nevow avoids any programmatic logic in the
    templates which means that all logic is directly in your python code
    (avoiding one of templating languages biggest faults - that of
    implementing *another* language just for templates).

    Templates now become a repository of html which is marked up with insert
    points, replacement points, patterns to reuse, etc. Sometimes you need
    to generate some dynamic html that won't easily and clearly fit into
    this 'extract patterns, replace sections, etc' pattern. When this
    happens you can either include bits of html as strings (yeuch!) *or* use

    Stan enables you to create small sections of dynamic html without
    recourse to templating languages or marking up tiny fragments of html
    for re-use.

    This section of code from the nevow forms library (this is a widget for
    file uploads).

    if name:
    if self.preview == 'image':
    yield T.p[value,T.img(src=self.fileHandler.getUrlForFile(value))]
    yield T.p[value]
    yield T.p[T.strong['nothing uploaded']]

    yield T.input(name=namer('value'),value=value,type='hidden')
    yield T.input(name=key, id=keytocssid(ctx.key),type='file')

    In other systems, this would have to be part of the template (via inline
    python or some alternative programming syntax), marked up as html in
    string elements (liable to validation errors and difficult to manage) or
    small fragments of html would have to be marked up as patterns and then
    manipulated in some fashion. The last is possible using nevow and the
    manipulation can be done directly on the produced html -- or via stan!!
    (think of manipulating a dom'ish like object).

    Tim Parkin
    Tim Parkin, Jul 19, 2005
  11. don't see why this would have problems 'scaling' or would be
    I think the difficulties will arise from the inability to visually
    track closing tags.
    Oh yeah, now I remeber, I think this is a controversial idea.

    istvan.albert, Jul 19, 2005
  12. You can do things like:

    t.p["This is some content"]

    This is not harder than normal xhtml tags to follow. plus you don't have
    to remember what tag you are closing :)
    Valentino Volonghi aka Dialtone, Jul 19, 2005
  13. One important thing to realise about Nevow is that it doesn't forbid you
    from putting logic in the template, it simply doesn't encourage it.
    There's nothing stopping you from writing render_while and render_if
    methods for Nevow -- in fact, it would be quite easy. But once you
    really understand Nevow and how it works, you realize that you don't
    need to put logic in the template, because there's a better way.
    Leif K-Brooks, Jul 20, 2005
  14. istvan.albert

    flupke Guest

    flupke, Jul 20, 2005
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.