dimanche 28 juin 2015

ImportError: no module named guardian

I'm new to Django, so generally I am the cause of most of my problems, but I can't figure out why the django-guardian 1.3 app won't install. I'm using Django 1.7 in a virtual environment, my OS is Windows 8.1.

I followed the installation directions at http://ift.tt/1TSMzxP and configuration at http://ift.tt/1LLuNHg, but I get an error when I attempt to run the program.

I added 'guardian', ANONYMOUS_USER_ID, and the backends to my settings.py

"""
Django settings for VolunteerManager project.
For more information on this file, see
http://ift.tt/WG84IA
For the full list of settings and their values, see
http://ift.tt/1s34S5Z
"""

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))


# Quick-start development settings - unsuitable for production
# See http://ift.tt/WG84IC

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'Super Super Secret'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

TEMPLATE_DEBUG = True

ALLOWED_HOSTS = []
ANONYMOUS_USER_ID = -1

# Application definition

INSTALLED_APPS = (
#DEFAULT APPS
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

#THIRD PARTY APPS
    'guardian',
    'registration',
        #Copyright (c) 2007-2012, James Bennett
        #All rights reserved.
    'django.contrib.sites',

#LOCAL APPS
    'Volunteer',
)

ACCOUNT_ACTIVATION_DAYS = 7 # One-week activation window;
REGISTRATION_AUTO_LOGIN = True # Automatically log the user in.

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

AUTHENTICATION_BACKENDS = (
    'django.contrib.auth.backends.ModelBackend', 
    'guardian.backends.ObjectPermissionBackend',
)

ROOT_URLCONF = 'VolunteerManager.urls'


#ANONYMOUS_USER_ID = 'VOLUNTEER_USER_ID'

WSGI_APPLICATION = 'VolunteerManager.wsgi.application'


# Database
# http://ift.tt/1s34S6b

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'volunteer',
        'USER': 'root',
        'PASSWORD': '$',
        'HOST': 'localhost',   # Or an IP Address that your DB is hosted on
        'PORT': '3306',
    }
}

# Internationalization
# http://ift.tt/WG863i

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# http://ift.tt/1s34R23

STATIC_URL = '/static/'

TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates')]

LOGIN_REDIRECT_URL = '/home/'

SITE_ID = 1

Error picture available on IMGUR

Django-guardian appears to be installed in my virtual environment, but it's still not finding it. Any ideas what I might have done wrong? (Or other suggestions for per-object permissions in Django?) Thank You!

UPDATE: I narrowed the problem down to the virtualenv. When I installed the modules without using virtualenv, then django finds them like it should. I'm still not sure what exactly I did wrong, but this works for now, considering that I'm only working on one project at the moment.

Aucun commentaire:

Enregistrer un commentaire