2

I have installed django-facebook in my Working application but it is creating a lots of problems. I have followed the installation of django-facebook here but I have not been able to implement it properly.

In facebook/example when I try to connect to facebook, it prompts the user for facebook credentials but it's not able to redirect to the next page as I am getting following error:

user or profile didn't have attribute facebook_id

I did manage.py syncdb but facebook attributes remain 'null' in DB after connecting to facebook in facebook/example.

I have added following to my code as in the documentation:

account/model.py

from django.db import models
from django.contrib.auth.models import User
from django.db.models.signals import post_save
from django_facebook.models import FacebookProfileModel

class User_info(FacebookProfileModel):
    user_id = models.ForeignKey(User)
    dob = models.DateField(blank=True, null=True)
    contact = models.IntegerField(max_length=20, blank=True, null=True)
    avatar = models.ImageField(upload_to='user_images', default='user_images/root.jpeg', null=True, blank=True)

def create_facebook_profile(sender, instance, created, **kwargs):
    if created:
        User_info.objects.create(user_id=instance)

post_save.connect(create_facebook_profile, sender=User)

settings.py

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'django.contrib.admindocs',
'account',
'django_facebook',
)

TEMPLATE_CONTEXT_PROCESSORS =(
'django.contrib.auth.context_processors.auth',
'django.core.context_processors.debug',
'django.core.context_processors.i18n',
'django.core.context_processors.media',
'django.core.context_processors.static',
'django.core.context_processors.tz',
'django.core.context_processors.request',
'django_facebook.context_processors.facebook',
)

AUTHENTICATION_BACKENDS = (
'django_facebook.auth_backends.FacebookBackend',
'django.contrib.auth.backends.ModelBackend',)

FACEBOOK_APP_ID = 'xxxxxxxxxxxxx'
FACEBOOK_APP_SECRET = 'xxxxxxxxxxxxxx'

urls.py

urlpatterns = patterns('',
url(r'^accounts/login/$',  login, {'template_name': 'login.html'}),
url(r'^accounts/logout/$', logout, {'next_page': '/accounts/login/'}, name='auth_logout',),
url(r'^accounts/signup/$', account.views.register, name='signup'),
url(r'^facebook/', include('django_facebook.urls')),
)

Please help me on this. Thanks.

Leonardo
  • 2,484
  • 2
  • 25
  • 37
D Dhaliwal
  • 552
  • 5
  • 23

1 Answers1

1

Did you specify your AUTH_PROFILE_MODULE in your settings.py ? Try to put:

   AUTH_PROFILE_MODULE = "yourApp.User_info"

Then syncdb and create a facebook account. It should do the trick.

Marcolac
  • 901
  • 4
  • 14
  • 27