Myghty
A template framework for Python
Python fan and advocate
What is Myghty?
- Templating Framework written in Python
- Originally ported from Perl's HTML::Mason to Python
- Compatible with:
- Apache and mod_python/cgi/wsgi
- CherryPy/Turbogears via "BuffetMyghty"
Getting set up
We'll assume the following:
- Apache 2.0.x is set up and running
- Mod Python is set up correctly
- You already know some python. :)
Prereqs
- Python 2.3.3 or greater
- Linux, OSX, Solaris, Windows 2000
- Apache 2.0/mod_python 3.1
We'll be assuming Linux for this presentation but it should work
for any OS
Install
Pretty straightforward:
- Set up Apache/mod_python
- Download lateset tarball from http://www.myghty.org/
- Extract tarball
- As appropriate user, run: python setup.py install
It is important to run the setup using the same install of python that
was used to install mod_python
What can we do with it?
- PSP pages
- Scopes
- Components
- Framework (autohandler and dhandler)
PSP Pages
- Regular HTML files interpreted normally
- Supports inline python code
- Supports embedded python code and blocks
Scopes
- Init
- Global
- Component
- Filter
Components
- Output buffered by default (important for redirects)
- Global variables "m", "ARGS", and "r"
Global variable "m"
- Called "the request"
- Controls component flow
- m.comp
- m.scomp
- m.send_redirect
- m.decline
Global variable "ARGS"
- Data comes from <%args> block
- Also available as m.request_args
Global variable "r"
- Available when using Myghty with one of the HTTPHandlers
- Reference to mod_python request object or compatible emulation object
- Access to various request variables such as:
- headers_in
- headers_out
- content_type
Component calling mechanisms
- /path/to/component_name.myt?var1=value1&var2=value2
- <& component_name.myt, var1 = value1, var2 = value2 &>
- m.comp('component_name.myt', var1 = value, var2 = value2)
Framework
- Requires directory setup
- autohandler - Wraps all components
- dhandler - Default handler
Cole's contact information