0

I am using django-guardian to handle object permissions. In my settings.py:

ANONYMOUS_USER_ID = -1

However, when I try to run the server, I get an improperly configured error:

django.core.exceptions.ImproperlyConfigured: In order to use django-guardian's ObjectPermissionBackend authorization backend you have to configure ANONYMOUS_USER_ID at your settings module

I suspect this may be due to the fact that I do from guardian.shortcuts import assign at the top of my settings.py, but I am not sure. Commenting out the import results in a successful server start, but trying to access any page gives me AttributeError: 'Settings' object has no attribute 'ROOT_URLCONF' which suggests that something is wrong with settings altogether (perhaps they are not being found correctly?).

arcologies
  • 742
  • 1
  • 6
  • 22

2 Answers2

1

I've just made myself sure that after following configuration instructions from http://packages.python.org/django-guardian/configuration.html project runs smoothly with guardian (using Django 1.4).

... and to answer your question:

  1. Try to avoid importing stuff inside settings module. If you do, make absolutely sure there are no circular imports issue. Actually, you have exactly that issue. If you need to, you can i.e. use *post_syncdb* signal: (https://docs.djangoproject.com/en/dev/ref/signals/#post-syncdb). In your case it shouldn't be needed, though, as you've already stated that removing that import fixed problem with running command (so settings module hasn't used assign shortcut anyway).

  2. ROOT_URLCONF attribute should definitely be set (it is if you generate project with Django's build-in command (i.e. django-admin.py startproject myproject). If it's missing, then yep, your configuration is broken. Try settings that attribute to something like 'myproject.urls' (or wherever your main urls are) and check if that fixes the problem.

lukaszb
  • 694
  • 1
  • 6
  • 15
0

For the record, I encountered the same issue with the last official release (installed with a simple pip install django-guardian)

This does not happen when you install the version from the lukaszb's git repository, I double checked the source code

bambata
  • 313
  • 1
  • 5