Pylons
Introduction
Pylons is a lightweight web framework emphasizing flexibility and rapid development
This page is an attempt to put together a list of common classes and functions that a Pylons developer will often need to access.
Documentation Links
- Python Language (Module Index | Language Reference)
- Core: Pylons API | Pylons Cookbook | WSGI Request/Response | WSGI Request Params | WSGI Environ Variables
- Components: Routes Manual | FormEncode | Beaker Session/Cache | Elixir
- Templates: Mako
Global Variables for Controllers
The following list is taken from Pylons Official Docs - Getting Started.
| object | description |
|---|---|
| session | Acts as a dict to store session data. |
| request | The request object |
| response | The response object, headers, cookies and status code can be set on this which will be used for the response |
| abort | Function to abort the request immediately by raising an HTTPException according to the specified status code |
| redirect_to | Function to redirect the browser to a different location via the HTTP 302 status code (by raising an HTTPException) |
| render | Function to render a template and return a string |
| h | Your project’s lib/helpers.py module. By default, this module exposes all functions available from the WebHelpers package. Keep in mind when reading the WebHelpers docs that all the functions listed should be prefixed by h. when used under Pylons. |
| c | (described in Passing Variables to Templates) |
| g | (described in Application Globals and Persistent Objects) |
| config | Dictionary-like object for accessing .ini file directives and other Pylons configuration options. |
| cache, etag_cache | Caching objects and functions. (described in the Caching in Templates and Controllers doc) |
| jsonify | Action decorator to format output as JavaScript Object Notation. |
| validate | Decorator for convenient form validation with FormEncode. (further described in the Form Handling document) |
| _, N_, ungettext | Internationalization / localization functions. (described in the Internationalization and Localization doc) |
| model | Access to your model package, however you choose to define it. |
Mako Templates Syntax
The code formatting in the examples are a bit off. The dumb wordpress editor doesn’t seem to save <code> and <pre> correctly in <table>.
| Name | Example |
| Expression Substitution | this is x: ${x} pythagorean theorem: ${pow(x,2)+pow(y,2)} |
| Expression Escaping |
${ "This is some text " | u,trim }
|
| Control Structure |
|
| Comments |
|
| Python Blocks | this is a template |
| Module-level Blocks | <%! |
| Page Tag |
|
Include Tag |
|
| Def Tag |
|
| Namespace Tag | <%namespace file="functions.html" import="*"/> |
| Inherit Tag | <%inherit file="base.html"/> |
| Call Tag |
<%call expr="buildtable"> |
| Text Tag | <%text filter="h"> |
WorkingEnv Commands
Only 2 commands that are important:
- To start the environment:
source <working-env>/bin/activate - To stop the environment:
deactivate









Add A Comment