01 - ZenTools Overview
In the vast sea of web frameworks out there today, there just don't seem to be any which truly simplify web development without getting in your way. ZenTools was created to fill this void. It's extremely easy to get started. It's incredibly easy to deploy. And when you want to do things your own way, ZenTools stays the hell out of your way.
Features
- Full Model-View-Controller architecture
- Full Object Relational Mapping
- script/shell for command line interface to models
- script/syncdb for database creation and syncing
- Innovative push-templating keeps templates clean, pure HTML
- Form population from Model objects
- Form validation
- Pagination
- Sessions
- File uploads
- Internationalization
- Email including email templates
- Extensive logging and error reporting
- Runs on any Mod_Python enabled web server
- Totally self-contained, modular applications for easy reuse
- Dynamic module-loading -- no need to restart the web server all the time
- Fully multi-threaded internals (ZenTools is really fast!)
- Drop-dead easy deployment
ZenTools in action
Let's take a peek at ZenTools in action. We'll start with just a simple layout and a static page. If you come from a PHP background, you might be accustomed to the old include header and footer statements at the top and bottom of each page. In ZenTools, we instead create a single layout file which contains a <div> tag with an id of "content" like this:
_layout.html
<html>
<head><title>Our Fancy Website</title></head>
<body>
<div id="content">
(page content will appear here)
</div>
</body>
</html>
Notice that there's no scripting code or even templating code. Just pure, valid XHTML with dynamic elements identified by an id attribute. Now let's look at the content file:
product-info.html
Title: Product Info
<h1 id="name">(product.name)</h1>
<p id="description">(product.description)</p>
Again, it's just pure XHTML with the exception of the first line which is called a "Page Setting". You can probably guess how that works just by looking at it (it overwrites the contents of the <title> tag in layout file). The bits of text in parentheses are for now just text. They're nice and readable and give us a pretty good idea of what will appear there.
So already, even without writing a single line of Python anywhere, ZenTools is making life easier. When a request comes in for "yoursite.com/product-info", the content will automatically get parsed into the layout, and the layout's title tag will be populated. You don't need a controller method and you don't need to define any "routes" anywhere for static content. Just drop an HTML file into the docroot and you're done. (Remember, the goal of ZenTools is to simplify!)
But what if you want to make it dynamic? For example, what if you want to populate the product name and description with something a bit more meaningful? For dynamic stuff, we just add a controller method.
We'll edit the site's controllers.py file to include a method which matches the filename, using underscores instead of hyphens. So the method name for product-info.html would be product_info() like this:
def product_info():
product = {'name':'Doo-Dad', 'description':'All about Doo-Dads.'}
html.content.format_with(product=product)
The html object contains all elements of your page which have an id attribute. And we use its format_with() method to replace those bits in parentheses with the actual values we've assigned for name and description.
But of course, you'll probably want to get your data from a database, right? That's even easier! Don't worry about the syntax if you don't understand it yet. For now, just take a look.
def product_info():
product = models.Product.get()
html.content.format_with(product = product)
But what if you only type six words per minute and can't stand that you have to write two whole lines of code in your controller method? Well, perhaps you'd prefer just one line then:
def product_info():
html.content.format_with(product = models.Product.get())
So that's just a teaser to demonstrate the "less is more" power of ZenTools. In case you're wondering, ZenTools gives you total control over every element of your XHTML that has an id attribute. The format_with() method is a handy shortcut that is very useful for many situations and there are other such shortcuts as well. But of course you aren't limited at all by these shortcuts and you can easily change, duplicate, or delete any element of your page however you like.
Use what you like
It's important stress too that you can use as little or as much of this stuff as you like. For many web designers, just the simplicity of ZenTools' static page and layout parsing is all they want. For those folks, there's zero learning curve. Download a ZenTools Starter and away you go. You'll never need to type a single line of Python. For developers who need a bit of dynamic control over some pages, it's easy to create simple controller methods. You can execute any Python code in these methods -- so do whatever you like! You don't have to use any ZenTools shortcuts if you don't want to. For application developers, you have the full power of a robust MVC framework with ORM and all of ZenTools' conveniences at your disposal. The point is: You don't have to spend a week studying and going through tutorials before you can start using the framework. Use what you need and move on to more advanced features as you need them.
Next: 02 - Quick Start