Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Example Facebook application powered by Fandjango
Latest commit d6e5b1c @jgorset Fix formatting
Failed to load latest commit information.
.gitignore Add dev.db to .gitignore Fix formatting Initial commit Initial commit Update to v4 Initial commit Update to v4

Fandjango Example

This repository consists of a sample Facebook application powered by the Fandjango library and a walkthrough to replicate it.


Register a Facebook application

First of all, we'll need to register a new application with the Facebook platform. To do so, go to and create your application. Once you have convinced Facebook that you are in fact human, you'll be presented with a daunting number of options. Don't worry, though; they're all optional and we only need to configure two of them right now:

  • App namespace - The URL you'd like your application to be accessed from, e.g.
  • Canvas URL - The URL that Facebook may load your application from, e.g.

Create a new Django project

Next, create a new Django project and install Fandjango:

$ startproject myfacebookapplication
$ pip install fandjango

Add fandjango to INSTALLED_APPS in your settings file.

Configure Fandjango

Fandjango needs some configuration. Specifically, you need to add its middleware to your middleware classes and specify your application's id, secret key and namespace (all of which can be found on in your settings file:

FACEBOOK_APPLICATION_SECRET_KEY = '214e4cb484c28c35f18a70a3d735999b'


Finally, synchronize your database to install Fandjango's models:

$ python syncdb

Note: If you're using Django's built-in CSRF protection middleware, you need to make sure Fandjango's middleware precedes it. Otherwise, Facebook's requests to your application will qualify cross-site request forgeries.

Develop the application


urlpatterns = patterns('',
    # Examples:
    url(r'^$', 'fandjangoexample.views.home', name='home'),


from django.http import HttpResponse
from fandjango.decorators import facebook_authorization_required

def home(request):
    return HttpResponse('Hello, %s' % request.facebook.user.first_name)

Sit back and enjoy

That's it! You have created a Facebook application that authorizes and greets its users. Navigate to your application's canvas URL to have a closer look at your new marvel of technology.

Where do I go from here?

You should read the documentation and browse the source code.

Something went wrong with that request. Please try again.