It’s been a year since Facebook changed the web with the open graph API and their like button. Unfortunately Facebook didn’t have much developer love for the python/django platform. Django Facebook aims to make it easy to build facebook apps and integrate facebook with your website.
One of the strong points of Django Facebook is the ability to register users using Facebook. It ports all of Facebook’s user data to the Django user and profile models. This allows you to have a secure register/connect/login flow using Facebook, greatly reducing the barriers to start using your application. Below an example of me registering for Fashiolista using the Facebook register flow.
Me on Facebook
Me on Fashiolista
In this blog post I will explain how to get started implementing a Facebook connect flow. Django Facebook can however do quite a bit more, as you can see in the feature list below. Development over at the github repo is very active. I strongly appreciate help on improving the functionality so please fork and contribute.
- Register users using the Facebook open graph API
- Full profile data birthday, gender, website, about me, username, email and picture
- Support for mobile authentication
- Fallback to registration form for entering additional data when required
- Build Facebook Canvas applications
- Mobile registration using Facebook
- Execute Facebook FQL queries
- Upload pictures to Facebook
- Find your Facebook friends
Now let’s get started with building a Facebook login/connect/register flow. This post will guide you through it step by step.
Have django registration installed (other registration systems will require some small code changes)
pip install django_facebook :)
A.) Settings and more
Define these settings in your settings file.
add django facebook to your installed apps
add this line to your url config
add this line to your context processors
add this to your AUTHENTICATION_BACKENDS
B.) Adjust your user Profile model
Secondly we need to be able to store the Facebook data on your user profile.
The easiest way to do this is to add the abstract model in django_facebook/models.py called FacebookProfileModel to your profile model.
After your profile is ready to store Facebook data you should have a working example at /facebook/connect/.
Let me know in the comments if something went wrong up to this point :)
C.) Design and integration
You can style the facebook form and button anyway you see fit. Over at Fashiolista we added a nice facepile for example. The basic markup is located in the example file connect.html.
That was all, you should now have a working registration flow using Facebook. Let me know in the comments if you encounter any difficulties.
If you want to go one step further and understand the facebook API, you can find the Facebook documentation here.
Django Facebook received tons of improvements from the python community. I’m certainly missing a few authors, but I would like to thank a few specifically:
Many thanks to (amongst many others)
- Kenneth Love
- Greg Taylor
- Riccardo Magliocchetti
- Mikhail Korobov
- Simple Geebus
- Jon Rohan
- Rick van Hattem
- Stochastic Technologies
- Can Burak Cilingir
- Michael Robellard
- Ramiro Morales
More posts coming up
- Building a facebook canvas app using Django Facebook
- Find and invite friends using Django Facebook
Do you also see the beauty in clean code? Are you experienced with high scalability web apps? Currently we’re looking for additional talent over at our Amsterdam office. Feel free to drop me a line at my personal email for more information: thierryschellenbach[at]gmail.com