我是新來的Django,所以通常我是我的大部分問題的原因,但我無法弄清楚爲什麼Django-guardian 1.3應用程序不會安裝。我在虛擬環境中使用Django 1.7,我的操作系統是Windows 8.1。ImportError:沒有模塊命名監護人
我按照安裝說明pythonhosted.org/django-guardian/installation.html和配置pythonhosted.org/django-guardian/configuration.html,但是當我嘗試運行程序時出現錯誤。
我說「監護人」,ANONYMOUS_USER_ID和後端到我的settings.py
"""
Django settings for VolunteerManager project.
For more information on this file, see
https://docs.djangoproject.com/en/1.7/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.7/ref/settings/
"""
# 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 https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/
# 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
# https://docs.djangoproject.com/en/1.7/ref/settings/#databases
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
# https://docs.djangoproject.com/en/1.7/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.7/howto/static-files/
STATIC_URL = '/static/'
TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates')]
LOGIN_REDIRECT_URL = '/home/'
SITE_ID = 1
Error picture available on IMGUR
Django的守護者似乎被安裝在我的虛擬環境,但它仍然沒有找到它。任何想法我可能做錯了什麼? (或在Django中針對每個對象權限的其他建議?)謝謝!
更新:我將問題縮小到virtualenv。當我在不使用virtualenv的情況下安裝模塊時,然後django發現它們應該像它一樣。我仍然不確定我做錯了什麼,但考慮到我目前只在一個項目上工作,所以這個工作現在可行。
在virtualenv產量中有'python -c'import guardian''是什麼? – dhke
python -c「import guardian」只是簡單地返回命令提示符而沒有錯誤信息,我認爲這意味着它正常工作。 –
是的,這意味着監護人模塊可以訪問。 django是否有可能認爲它應該使用站點範圍的包而不是virtualenv包?你是否安裝了django並在virtualenv中初始化了該項目? – dhke