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:

http://127.0.0.1:5000/

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.

What do you have to say?

Show Editing Help


About

Hello, my name is Zeth, I'll be your host here.

Command Line Warriors is about taking control of your own technology, it looks at our experiences of computing; especially using GNU/Linux, the Python programming language, the command-line and issues such as techno-ethics, best practices and whatever is cool now. If you take control of your technology then you are a Warrior too!

This site is your site too which means that you can contribute and get involved. You can leave comments using the facility provided. For me, the comments and discussions are by far the best part of the site. So please do have your say!

Latest Discussions

Omar Zabaneh

July 25, 2008
Zeth, Thank you for this post, very helpful. I used it as a basis for my own email validation function that i wish to share with you, in a selfish ...
Email Syntax Check in Python

Double Booting Bastard

July 24, 2008
I agree with Nui, Linux is great for many things but not everything. A lot of, less mainstream, hardware is a time consuming and often fruitless task to install and ...
Give Linux a chance

John

July 23, 2008
Duncan, sadly the permissions are stored with the data (inode), not with the directory entries (hard-links). Zeth needs ACLs -- no way to do this with basic unix permissions.
Advanced Unix Groups

Garrick

July 21, 2008
I do love my iPhone. That being said, I would trade it in a heartbeat for a STABLE Openmoko FreeRunner.
This week - iPhone vs a can of compressed air, and Django NewFormsAdmin

Daniel Davies

July 21, 2008
With regards to your last paragraph, you are certainly correct. Right now Django is a nightmare to use across multiple sites... we have some sites running the newformsadmin branch, others ...
This week - iPhone vs a can of compressed air, and Django NewFormsAdmin

Nui

July 18, 2008
Hmm, this would be more persuasive as an argument with some evidence. I am a happy admin of Windows and a novice user of Linux, so I have taken the ...
Give Linux a chance

Paddy3118

July 18, 2008
Hi, I too work with Electronic Design Automation tools, where Tcl is used extensively. I tend to only occasionally have to write in Tcl and so find the TclTutor utility: ...
Python and TCL

Cliff Wells

July 17, 2008
I personally cannot live without the Web Developer extension or Firebug. Unfortunately these are probably both among the more difficult to port extensions. Given how poorly Firefox functions on Linux ...
Will Epiphany be able to compete with Firefox's extensions?

Åke Forslund

July 13, 2008
I'm pretty much a novice in both of these languages but I find them both easy to use and preform the tasks I give them. However I rarely use them ...
Python and TCL

Christopher Thoday

July 12, 2008
A single test is not sufficient to give you confidence that the algorithm is working. You should make 'number' an argument of 'main' so that you can test some boundary ...
Python and TCL

paul21

July 10, 2008
Shame on Mozilla. They should make developers specify the extension license before hosting it. They should show the license next to download button as well.
Are your Firefox extensions proprietary software?

Tris

July 8, 2008
Justin - You say they had not heard of Linux? That doesn't sound very professional to me!
Give Linux a chance

michael

July 8, 2008
what about Galeon? in Gnome i use Galeon mostly. it is fast and stable and has a nice portal with search masks for Debian, FSF, Freshmeat and so on. wtf ...
Will Epiphany be able to compete with Firefox's extensions?

vermin

July 7, 2008
> Eventually, after a bit of digging and Googling, I found their Toolbar-License... You simply found the license of the StumbleUpon Toolbar for Internet Explorer. This is another product, much ...
Are your Firefox extensions proprietary software?

Andrew West

July 6, 2008
Both the Python and the Tcl example could do with error checking. While at first this may not seem on topic with the post I think it better shows the ...
Python and TCL