10

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 !

Community
  • 1
  • 1
iva123
  • 3,395
  • 10
  • 47
  • 68

3 Answers3

13

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.

wunki
  • 653
  • 6
  • 13
  • 4
    I'm having trouble getting this to work. Unfortunately the userena docs aren't very... descriptive when discussing how to properly set up `AUTH_PROFILE_MODULE`. From reading your link, I created an app called 'accounts' and added something similar to their [MyProfile](http://docs.django-userena.org/en/latest/installation.html#installing-django-userena) to that models.py named `UserProfile`. Then in settings.py I set `AUTH_PROFILE_MODULE = 'accounts.UserProfile'`. However it throws a SiteProfileNotAvailable exception when I visit any URL on my site now. – Chris Ballinger Sep 25 '11 at 00:24
  • 6
    Chris, I was just having the same problem, and figured I should share the solution in case someone else comes across this. For me the problem was that I forgot to `syncdb` after installing all these new apps. And then once I did that, I realized there were some typos and missing import statements in my `accounts/models.py` that it hadn't complained to me about. Once I fixed `models.py` and successfully `syncdb`'d, everything was fine. – floer32 Oct 23 '11 at 21:16
7

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.

Peter Boyer
  • 1,037
  • 9
  • 5
  • Q: "your subclass of UserenaBaseProfile or UserenaBaseProfile"? Aren't those two the same? Also, 'setting.py' should be 'settings.py'. Also, Welcome to StackOverflow! – Anuj Gupta Oct 02 '12 at 11:56
  • Hi Anuj, I fixed the two errors you pointed out. Thanks for pointing them out. – Peter Boyer Oct 02 '12 at 16:57
  • This answer saved me a ton of time. I didn't realize I forgot to add the accounts app when I was following the installation instructions; totally overlooked it! – Alastair Mar 31 '13 at 18:06
4

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 = 'yourgmailaccount@gmail.com'  
    EMAIL_HOST_PASSWORD = 'yourgmailpassword'  
    
    1. Go to your Command Prompt shell and type:

      python manage.py check_permissions

run /accounts/signin/

Algorithmatic
  • 1,824
  • 2
  • 24
  • 41
Smita K
  • 94
  • 5