Django Installation on Mac OS X Lion

Like many of Apple fanboys out there even I decided to upgrade Mac OS X Snow Leopard (10.6) to Mac OS X Lion (10.7) as soon as it was made available on App Store. Upgrading from App Store was pretty smooth and was surprised it did not break any apps (May be that’s because it’s just an incremental upgrade with some fancy features) except my Django projects failing to validate because of the default python version change (from 2.6.x to 2.7.1) and can be easily fixed. However I decided to go for fresh install of OS X Lion to test how fresh install (wipe out disk after backup and install ) works with OS X Lion.

Once done with fresh installation of Mac OS X Lion, immediate task was setting up my development environment which includes MySQL server, phpMyAdmin and Django.

Steps I followed to get Django development environment back are as below

  1. Install Xcode via Mac OS X App Store ( Might be required when you compile and install from source)
  2. Install MySQL Server
  3. Install phpMyAdmin
  4. By default jpeg, freetype, littlecms image library support is missing, you need to install at least jpeg support so ImageField in your django project supports jpeg formats.
    1. Install JPEG libraries
      1. Download JPEG library source curl -O
      2. Extract tar -xvzf jpegsrc.v8c.tar.gz
      3. Switch to jpeg directory cd jpeg-8c
      4. Run ./confgure
      5. Run make
      6. Run sudo make install
    2. Install Freetype libraries
      1. Download Freetype library source curl -O
      2. Extract tar -xvzf freetype-2.4.5.tar.gz
      3. Switch to freetype directory cd freetype-2.4.5
      4. Run ./configure
      5. Run make
      6. Run sudo make install
  5. Install Django using sudo easy_install django
  6. Install Python Image Library (PIL) using sudo easy_install PIL
  7. Install mysql-python driver using sudo easy_install MySQL-python (Make sure you got mysql in your PATH, otherwise this will fail with mysql_config not found error)

That’s all you need to go ahead and start creating Django projects. However I prefer using virtualenv for all my Python projects. If you take this route, you can use pip install <package_name> to install necessary packages for example pip install django, pip install MySQL-python, pip install PIL to install Django, MySQL Python driver and Python Image Library.

Update 1 (25/07/2011): If you get error “django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: dlopen(/Users/xxx/xxx/pyprojects/xxx/lib/python2.7/site-packages/, 2): Library not loaded: libmysqlclient.18.dylib
Referenced from: /Users/xxx/xxx/pyprojects/xxx/lib/python2.7/site-packages/
Reason: image not found”, when you validate your project or try to use MySQL-python,

Type export DYLD_LIBRARY_PATH=”$DYLD_LIBRARY_PATH:/usr/local/mysql/lib/” in your terminal and see if problem persists. You can add it to your .profile file to make this persistent so you don’t need to run it every time.

Practical Django Projects Book Review

I’ve started working on Python & Django sometime around March 2008 and from then on started following Django IRC and Django blogs of which b-list by James Bennett is most useful/helpful till date. Also I use django-registration django resuable app by James Bennett in all of my projects (even today) and hence I decided to order  the book Practical Django Projects by James Bennett in July and I was expecting to learn something new which is not in my arsenal.

Continue reading

WYSIWYG Editor for Django

Lately I’ve been working on CMS like application for a news portal and one of the major features include integrating WYSIWYG editor to enable journalists post news online with ease. With almost zero expertise in Javascript, I thought this will be a difficult activity but it turned out to be very easy and took less than an hour to integrate once we shortlisted on which editor we will be using.

Continue reading

Django Timestamp without using auto_now and auto_now_add

If you have ever used/worked on CMS/Blogging apps, you might have noticed created and last updated timestamp’s for each content item (article/entry) and as you would expect Django also provide two options for DateTimeField which will enable you to create timestamps automatically. DateTimeField with option auto_now_add ( models.DateTimeField(auto_now_add=True) ) can be used for created timestamp while DateTimeField with option auto_now ( models.DateTimeField(auto_now=True) ) can be used for last updated timestamp. Only drawback of auto_now and auto_now_add is they disable editing timestamps from admin.

Continue reading

Installing Django on windows

Well if you have decided to install Django, by now you must be knowing Django is a Python based web framework and in today’s post I’ll run through Django installation process on Windows including dependencies (like installation of Python, database, database adapters and other important libraries that Django depends on). If you already have Python installed, then skip Python installation section.

Installing Django/Python/Python modules is same in all versions of windows and hence below steps are valid for Windows XP and Windows Vista. Those who are using Windows Vista, just make sure you run all installations as Administrator ( Right click setup file and run as administrator )

Let’s begin by installing Python (If you already have a working Python installation, skip this section)

Continue reading

Why Django blog with WordPress ?

Reading about Django related stuff on WordPress (PHP) powered blog might be disrespectful to simple yet powerful Python based framework like Django, which let’s you create a decent blog within couple of hours. But I don’t think this site will end up as just an another blog and if at all it end up as a blog due to laziness then I’ll sure replace this one with Django based blog which has all important wordpress features I’m looking for like comment moderation (IP and keyword filtering), SEO, WYSIWYG editor, Akismet integration, Tagging to name a few which are often ignored by many developers out there.

I’m pretty sure all those features are on mind of some of the programmers and we will see an blog app soon  but if they delay longer then I may end up writing one to move this from wordpress to Django.  Anyways we will have a migration guide from WordPress to Django as another post in form of  my migration experiences when when I migrate. Till such time, I’ll use Django badge I wish this site were powered by Django on footer.