Fixing DreamHost’s Django Deployment Script

I recently created a trivial site locally with Django that I wanted to deploy on my DreamHost shared server.  DreamHost has made this process pretty painless by creating an easy-to-follow guide that can be found here.  The only problem is that it doesn’t work.  After entering in my project name and database info, i got the error message:

Creating project framework…  oops, django-admin failed to run!

With nothing to lose (and not wanting to figure out how to get Passenger set up on my own), I dove into their django-setup.py script.  As it turns out, the problem is on line 126.

if os.spawnl(os.P_WAIT, "/usr/bin/django-admin.py", "django-admin.py", "startproject", projname) != 0:

Apparently on DreamHost, django-admin.py has dropped the extension. So if you replace line 126 with the following, everything works great.

if os.spawnl(os.P_WAIT, "/usr/bin/django-admin", "django-admin", "startproject", projname) != 0:

Django Power!

Over the past month I’ve been dabbling with Django by starting to convert the prototype of Mail Tally (PHP) into a useable site powered by it.  So far I have to say that I love it!  The template inheritance is mind blowing, and the ease of mapping URLs to views just blows my mind.

It’s embarrassing to say that I’ve never used a proper PHP framework before.  At my day job we have an in-house CMS that has some MVC leanings, and prior to that I’ve done a lot of work in WordPress.  It’s refreshing to write web apps with a framework that makes it fun.

Learning How To Hack

I’m putting this here as a resource to myself, as well as to others.  If you’ve ever been interested in learning to become a better programmer, this resources is for you.

http://krainboltgreene.github.com/l/2/

Beginning to advanced Python, Ruby, and software development practices are covered here with links to free PDF books to help you learn.  I highly suggest taking a look.

Choosing a Python Web Framework

If you follow this blog at all, you know that I’m a PHP programmer.  Specifically, I like to work the LAMP stack.  Lately though I’ve been getting the itch to grow my Python skills and learn a new web framework.  After some searching about on the internet, I came up with two Python web frameworks that look promising: Django and Pylons.

Django and Pylons are both Python web frameworks that encourage rapid development of web sites using the Model-View-Controller design pattern.  They both are similar, but also have enough differences to warrant some discussion before choosing one over the other.

From my research and experience, Django is good because it’s easy.  It’s easy to set up a site and the administrative interface is built up for you.  The only issues people have is that it doesn’t allow a great deal of customization, and sometimes Django hides what is going on from you.  To some people this is desirable, to others it isn’t.

People seem to like Pylons because it’s extremely flexible.  For your models you can use SQL Alchemy or some other ORM, while for your template engine you can use Mako or any other kind that you’d like.

Mainly because I like to have flexibility, I think I’ll start out with Pylons.  If you’re interested in learning more about the differences between the two frameworks check out this and this.

Getting Started with Google App Engine [Part 1]

For longest time I’ve done web development exclusively in PHP.  Lately however I’ve been looking for something a bit different to play with.  I already know Python (not well of course, but that’s changing), so I thought I’d look into web app development using that.  The most obvious way to develop web apps with Python is with a framework like Django or Pylons, but I was interested in scalability too.  Actually, I was interested in EASY scalability.  This is where Google App Engine and their WebApp framework steps in.

What is Google App Engine?

Google App Engine (GAE) is a platform for building highly scalable web applications on Google’s infrastructure.  So what does that mean for you?  It means you can use Python or Java to create web sites hosted on Google’s servers.  The main benefit of using GAE is scalability.  Google’s infrastructure is ridiculously huge, and having access to that means basically unlimited scalability.  You also get to access this all for free, and after you reach the free quota limits, you pay only for what you use.  For more information on quotas for the free service, click here.

Getting Started

Now that you’re interested, you probably want to try it out.  Before you can do that though, you need to create a GAE account and download the development environment.  Development environments are available for Windows, Mac, and Linux.  Setting up the environment is fairly straight forward, and all directions from this point forward should work for you regardless of your platform.  More information about setting up the development environment is available here.

A Simple “Hello World”

Keeping with the spirit of programmers everywhere, I’m going to start off with a simple “Hello World” program.  The first thing you need to do is create a directory called helloworld in the GAE directory.  After that, create 2 files in the new directory called helloworld.py and app.yaml.  Add the following to those files.

helloworld.py

print 'Content-Type: text/html'
print ''
print 'Hello world!'

app.yaml

application: helloworld
version: 1
runtime: python
api_version: 1
 
handlers:
-	url: /.*
	script: helloworld.py

So let’s explain things a bit.  The first file helloworld.py, is straight forward.  The first line sets the content type to HTML, prints a new line, and then prints “Hello world!”.  The second file app.yaml, is a little more complicated.  Here’s the breakdown:

  • application – The name of the folder containing the application.
  • version – The version of the app you plan to upload to GAE.  Increment this every time you are going to upload to GAE and it will keep track of your different versions.
  • runtime – This is the language you are writing the app in.  Python is what we’re using, but Java (lowercase) is also an option.
  • api_version – The GAE api version that we are using.  1 is usually a good choice here.
  • handlers – This essentially maps the url path to a python file.  Once you start the web server, by going to any URL you will be routed through the helloworld.py script.  If you wanted http://localhost/hello to go through helloworld.py, the you would change “url” to “/hello”.

Once those files are in place, running the app is easy.  Let’s assume that the helloworld script is in a directory called helloworld within my Google App Engine directory.  With that assumption, you run:

google_appengine/dev_appserver.py helloworld/

Next Time…

In the next part of this series, I’ll talk about getting started with submitting forms, storing information in the data store, and using templates.