Pylons part 2 - Getting Pylons
30 September 2007
Install Pylons
In the last part we got easy_install working. Now we can start properly and get Pylons installed. You will need to run the following command as root:
easy_install -U -f http://pylonshq.com/download/ Pylons==0.9.6
This grabs Pylons 0.9.6 from the Pylons website and installs it.
If you are reading this post a long time after publication, then the version number may well be different.
We also need SQLAlchemy, the required version 0.4, is not available through automatic download, so go get it, and then run
easy_install /tmp/SQLAlchemy-0.4.0beta5.tar.gz
Create the project
Now go to the directory you want to work in (e.g. cd ~/sandbox ). From now on you want to be a normal user (not root).
paster create -t pylons QuickWiki
This command will create the basic structure of a Pylons web application. Have a little fish around and see the directory structure that has been created.
You will notice there is a development.ini and there is a directory called quickwiki (i.e. with a small starting letter). Inside that directory, you will find the following directories:
model
templates
controllers
If you have used any other framework like Ruby-on-Rails or Django then you will recognise these terms, it is basically like the Model-view-controller.
Model view controller
> "Just as web standards seek to separate content, presentation, and behavior, MVC seeks to separate data, interface, and logic." (source)
So in Pylons, the model is your data, in the model folder you write a file that tells SQLAlchemy to make the database do what you want.
The view is what the visitor to the website can actually see, so in the 'template' folder you write templates in the mako template format.
Lastly, the controllers are the interesting bit, the 'controllers' folder holds your Python code, the application logic, the intelligent bit.
Confusingly enough, Django calls the 'view' the 'template' and the 'controller' the 'view', but the general concept is the same.
There are also some other folders. 'public' contains static files that we want to be able to display on the web directly. You will notice that it already contains an index.html file.
We will ignore 'config', 'lib', and 'tests' for the moment, you may be able to guess already what they do.
Now get back up to the QuickWiki directory, the one that contains development.ini.
Testing the server
Let's start the server:
paster serve --reload development.ini
Now open a web browser and go to the following URL:
You can now see the index.html from your 'public' directory.
That's all for today, If you want to carry on alone then jump to part four of the tutorial. From here we will probably go our own way, rather than following the tutorial exactly.


