foundev.github.io

Python Web Framework Series – Pylons: Part 1 Getting Started

This article assumes you have Python 2.6 and Setuptools already installed on your machine and that you’re install SQL Alchemy 0.54 and Pylons 0.97

Overview

Pylons is a component based MVC web framework. It, like a lot of more recent MVC frameworks, is borrowing some ideas and concepts from rails  in a less “opinionated “ way.

Out of the box Pylons has a preference for using SQL Alchemy for ORM (similar to NHibernate in philosophy) and Mako template engine (uses Python code for markup) .  Now if you prefer SQLObject , or the Elixer dialect of SQL Alchemy for ORM and Genshi template engine pylons supports them all (and others).  More importantly this means you have choice down the road to match your personal preferences or particular project complexity needs.

 

Installation

With Setuptools installed Pylons installation is type the following in a command prompt:

<i>easy_install Pylons</i>

<i>easy_install SQLAlchemy</i>&nbsp;

This will install everything needed to get started.

###

Pylons Forum

Were going to create a simple forum called Pylons Forum. Not exactly imaginative, but it requires authorization, db calls, and basic view logic. Just be glad its not a shopping cart or blog.

Typing __

paster create –list-templates

Picture 1

We’re going to use the pylons template for now and type

paster create –t pylons pylonsforum

 Picture 2

 

select enter to pick ‘mako’, then you’ll see:

 Picture 4

 

 

type in true then hit enter.

cd into the pylonsforum directory and run dir(or ls depending on your platform)

should result in:

Picture 5

Now if this is what you see the key being “development.ini” file. Type

paster serve –reload development.ini

Picture 11

open up a browser to http://127.0.0.1:5000

 

Picture 8

 

First Controller and Test

Now that we have our structure setup go ahead and type the following:

<br />

<br />

<br />

<br />

<br />

cd pylonsforum

paster controller home

 

you should see:

Picture 12

So we’ve created a controller and a functional test associated with that controller.

open the following url:

http://localhost:5000/home/index

will bring up the obligatory “hello world”.

Next post I’ll being to cover using controllers and views.