Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configuring django-userena

for my new project I decided to use django-userena

I followed the instructions from userena docs. However I'm getting this error :

SiteProfileNotAvailable at /accounts/signin/

No exception supplied

and don't know how to fix it. Please help !

like image 608
iva123 Avatar asked Jul 24 '11 20:07

iva123


3 Answers

You usually get a SiteProfileNotAvailable when Django can't find your profile. As documented in the "Storing additional information about users", you need to define AUTH_PROFILE_MODULE to point to the model of you profile.

like image 177
wunki Avatar answered Nov 09 '22 13:11

wunki


As wunki has aptly pointed out, it's important to define the AUTH_PROFILE_MODULE in your settings.py file to point to your subclass of UserenaBaseProfile or UserenaLanguageBaseProfile. As discussed in the userena tutorial, these are usually placed inside of the models.py file of your newly created 'accounts' project.

However, I've found that the python manage.py runserver will fail if you have already provided AUTH_PROFILE_MODULE. If you have provided AUTH_PROFILE_MODULE and still receive a SiteProfileNotAvailable error (on every URL of your app), it may be that you failed to add 'accounts' to your list of INSTALLED_APPS in settings.py.

like image 43
Peter Boyer Avatar answered Nov 09 '22 12:11

Peter Boyer


Try following step:

  1. In your settings.py file, add ’userena’, ’guardian’, ’easy_thumbnails’ to your INSTALLED_APPS tuple.

  2. Then again in your settings.py file, add the following:

    AUTHENTICATION_BACKENDS = (  
        'userena.backends.UserenaAuthenticationBackend',  
        'guardian.backends.ObjectPermissionBackend',  
        'django.contrib.auth.backends.ModelBackend',  
    )  
    
    ANONYMOUS_USER_ID = -1  
    

The above is used to get django-guardian working (another Django-Userena dependency that’s automatically installed to control permissions)

  1. Next, create a new app for your Django-Userena app. In your Command Prompt shell, type: python manage.py startapp accounts. We are creating a new app for Django-Userena titled ‘accounts’.

  2. Now add accounts to your INSTALLED_APPS tuple in your settings.py file.

  3. Copy the following into accounts/models.py:

    from django.contrib.auth.models import User  
    from django.utils.translation import ugettext as _  
    from userena.models import UserenaBaseProfile  
    
    class MyProfile(UserenaBaseProfile):  
        user = models.OneToOneField(User,unique=True,  
                      verbose_name=_('user'),related_name='my_profile')  
        favourite_snack = models.CharField(_('favouritesnack'),max_length=5)  
    
  4. Next add the following into settings.py file :

    AUTH_PROFILE_MODULE = 'accounts.MyProfile'  
    
    LOGIN_REDIRECT_URL = '/accounts/%(username)s/'  
    LOGIN_URL = '/accounts/signin/'  
    LOGOUT_URL = '/accounts/signout/'  
    

The ‘accounts.MyProfile’ in AUTH_PROFILE_MODULE refers to the app ‘accounts’ containing the model class MyProfile as we defined earlier. The 3 login/logout URL statements tell Django where to have the URLs for Django-Userena to work.

  1. Add the following into urls.py under the ‘urlpatterns’ tuple:

    (r'^accounts/', include('userena.urls')),  
    
  2. Configure your Django SMTP email settings to use Gmail in settings.py:

    EMAIL_USE_TLS = True  
    EMAIL_HOST = 'smtp.gmail.com'  
    EMAIL_PORT = 587  
    EMAIL_HOST_USER = '[email protected]'  
    EMAIL_HOST_PASSWORD = 'yourgmailpassword'  
    
    1. Go to your Command Prompt shell and type:

      python manage.py check_permissions

run /accounts/signin/

like image 31
Smita K Avatar answered Nov 09 '22 12:11

Smita K