Python embedded like PHP

Paul Boddie paul at boddie.net
Sun Mar 31 11:20:10 EST 2002


I wrote:
> > In the Python community, there is obviously an intense interest in
> > templating, but I haven't seen more than a handful of validation
> > packages, and I can imagine that few of them actually integrate
> > satisfactorily with template packages.

Jon replied:
> I'm not sure what you mean here. Can you give an example of what a
> "validation package" might do?

The way I see things, when developing Web applications, is as follows.
First of all, developers need to present some state of the
application, and this is where template systems first get used. Of
course, as I noted in my previous response, it depends on the nature
of the application (and how the development work on the application is
organised) as to whether you prefer HTML-in-Python or Python-in-HTML
or some "more neutral" template language.

If the nature of the user responses to a particular "screen" are of
more than limited complexity, it becomes tiresome to manually code
HTML form tags, and this is where certain template solutions provide
some help to developers. For example, JavaServer Pages provide "custom
tags" which can be used to substitute commonly-used output into pages
in a nicer way than "home-made" solutions (since the designers did
think about the re-use of tags across applications, and there's a
reasonably powerful object model for tags to plug into).

The next problem, though, is coordinating the output with the input.
One can invent a "custom tag" (or corresponding feature in one's
framework of choice) which emits an HTML "input" field, but where is
the code that checks the value returned by the user through that
field, and how can we be sure that such code is validating and
manipulating the same kind of data as that described by the "input"
field? For example, I could invent a "custom tag" like this:

  <myapp:specialInput name="someField"/>

This could result in the following HTML being generated:

  <input name="someField" size="30" type="text">

The intention might be that the contents of "someField" are in a
particular format. Moreover, such data may be stored in a database
system, and we might want to keep the "size" or "length" of a piece of
data synchronized with the data type used in the database - it's not
uncommon for such things to evolve as the requirements of an
application change, but it would be very inconvenient to need to
change HTML form descriptions, validation code, template system code,
all in a number of different places.

Template systems typically don't address these issues, whereas
stand-alone validation systems address the nature of the input data
but not how such data is "described" to the browser (and thus to the
user). A coordinated approach which unifies input, output, and
validation seems to be the logical next step in any significantly big
or complex application.

Paul



More information about the Python-list mailing list