A Python web framework that makes the most of the
Simplates are the main attraction.
Simplates are the file format Aspen uses to represent HTTP resources. They are Aspen’s main attraction. Here’s what a simplate looks like:
"""This is my simplate. """ import random [---] n = random.choice(range(10)) extra_excitement = "!" * n [---] Greetings, program!%(extra_excitement)s
Simplates are a single file with one or more pages. The page separator is
Assuming you’ve gone through the Quick Start, edit index.html.spt with the above content, then refresh.
You’re off and running!
Give it a shot: Anything you define in the first two (Python) pages is available in the third (template) page.
Can you guess what the difference is between the first two Python pages? The first one is run once, the first time the page is hit (not on startup), and again any time the simplate is changed. It’s designed for imports and constants. The second is run once for each request.
The first page has these variables defined and available to you:
__file__ the absolute path to the simplate file (symlinks preserved) website an instance of a Website object that gives you access to configuration objects
The second page has those, and adds:
request a request object response a response object
The template page uses the template language from python by default, though others are available.
All simplate pages are cached in a compiled state. This cache is invalidated whenever the underlying file changes, so simplate changes are always immediately available. When you change Python libraries or configuration files, aspen can restart automatically. But even this extra second or so is a drag during development. When you change a simplate, the changes are always available immediately, without restarting the server.
Aspen uses the simplate file format to represent four different kinds of resources. Media types are inferred from the file extension.
Well, I like to think that simplates bring code and presentation as close together as possible without mixing them. There are no arbitrary Python blocks inside of the template page, à la PHP/ASP.
Simplates are more like MVC, but with controllers, views, and templates together in the same file instead of in separate files. Your models live in a Python library, use an ORM, etc. And URL routing is done via the filesystem. There’s all around less boilerplate.
Don’t be scared! This isn’t PHP! It’s MVC with less crap.
My friend Steve came up with the original idea for simplates in the early aughts, when we were running a web design shop together. We were heavily into Zope and Plone at the time. This was in the Zope 2 days. The original idea was something like, “What if you could put a Script (Python) and a ZPT in THE SAME FILE!?” Steve has since switched careers to philosophy. I debuted simplates in Aspen 0.8, which came out in December of 2007. I made simplates the main attraction in Aspen 0.9.Home Request