Installing psycopg2 on Mac 10.6.4 Snow Leopard

Setting up Django for use with Postgres 8.3. Django uses psycopg2 (or psycopg depending on what you choose). To the best of my knowledge psycopg2 v2.2.2 is the most stable version of the code.

easy_install "psycopg2=2.2.2"

Then edit your file for Django.

DATABASE_ENGINE = ‘postgresql_psycopg2’

Psycopg2 Error

The easy_install for psycopg2 didn’t work immediately because easy_install could not find pg_config and caused compile process failed. To fix the problem I needed my environment to have access to Postgres 8.3 pg_config. The default MacPorts install of Postgres 8.3 drops pg_config and other key files into /opt/local/lib/postgresql83/bin/ .

To allow your easy_install environment to see pg_config, simply symbolically link it to your ~/bin directory. It does not have to be ~/bin. It could be any directory on your environment path. Just pick something easy.

# symbolic link from MacPorts install of postgres to a path on my home dir.
ln -s /opt/local/lib/postgresql83/bin/pg_config ~/bin/pg_config

I edited my .bash_profile so that the files in ~/bin is always on my environment path.

# set PATH so it includes user’s private bin if it exists
if [ -d ~/bin ] ; then
if [ -f /opt/local/etc/bash_completion ]; then
    . /opt/local/etc/bash_completion

Django RSS feed aggregators

The plan — integrate RSS feeds into my crappy car website. Re-syndicating many feeds from (List of feeds)


On the Toyota page of my site, display snippets from the Toyota feed.


Mark Pilgrim’s Feed Parser

Django Reader


How-To customize Aggregator

Access variables from Django Templates

My goal is to conditionally include google analytics tracking on my Django templates depending on whether settings.DEBUG is on or off as defined in my file. To accomplish you can write a template context processor that returns the variable with the request context which will make the variable values readable in your Django Templates.

First, add a to the folder for your app (my app is called auto)

Next, copy and paste the function into As you can see we are simply stuffing the settings variable onto the request object.

def debug_mode(request):
    from django.conf import settings
    return {‘debug_mode’: settings.DEBUG}

Now, we add our context processor to the TEMPLATE_CONTEXT_PROCESSORS section in If you do not have this section, add it. It won’t break anything.


Next we have to use the RequestContext. Add this import statement to

from django.template import RequestContext

Now, set context_instance for all of your template render calls.

def detail(request, template_name="myview.html"):
    return render_to_response(template_name, context, context_instance=RequestContext(request))

Finally, you can see if settings.DEBUG is True or False in your Django Templates!

{/span> if debug_mode }
<h1>We are debugging!</h1>
{/span> endif }

Reference: Django Tips: Template Context Processors

Syndicate content