python - 安装 Pillow 后出现 ModuleNotFoundError
问题描述
无论我去哪个链接,HTTP 都会给我 ModuleNotFoundError。
ModuleNotFoundError 给了我以下信息:
ModuleNotFoundError at /web/
No module named 'django.core.context_processors'
Request Method: GET
Request URL: http://127.0.0.1:8000/web/
Django Version: 3.1.5
Exception Type: ModuleNotFoundError
Exception Value:
No module named 'django.core.context_processors'
Exception Location: <frozen importlib._bootstrap>, line 984, in _find_and_load_unlocked
Python Executable: /Users/william/Documents/coding/WDTP/wfw_fixed/env/bin/python3
Python Version: 3.9.0
Python Path:
['/Users/william/Documents/coding/WDTP/wfw_fixed/wfw',
'/Library/Frameworks/Python.framework/Versions/3.9/lib/python39.zip',
'/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9',
'/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload',
'/Users/william/Documents/coding/WDTP/wfw_fixed/env/lib/python3.9/site-packages']
Server time: Sat, 23 Jan 2021 00:07:14 +0000
自从我安装了 Pillow 以来,它就一直在发生。
在我的settings.py
:
"""
Django settings for wfw project.
Generated by 'django-admin startproject' using Django 3.1.5.
For more information on this file, see
https://docs.djangoproject.com/en/3.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.1/ref/settings/
"""
from pathlib import Path
import os.path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# Test for settings templates path
SETTINGS_PATH = os.path.dirname(os.path.dirname(__file__))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'wfw_editor.apps.WfwEditorConfig',
'feedback.apps.FeedbackConfig',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'wfw.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates'),],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'django.core.context_processors.i18n',
'django.core.context_processors.media',
'django.core.context_processors.static',
'django.core.context_processors.tz',
'django.core.context_processors',
],
},
},
]
我认为我不需要以下部分,但我还是发布了它:
WSGI_APPLICATION = 'wfw.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
# Password validation
# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/3.1/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/3.1/howto/static-files/
STATIC_URL = '/static/'
我删除了 SECRET_KEY 变量。问题是否发生在settings.py
? 问题是因为我没有导入一些东西吗?
解决方案
您的意思是导入django.template.context_processors.*
而不是:
'django.core.context_processors.i18n',
'django.core.context_processors.media',
'django.core.context_processors.static',
'django.core.context_processors.tz',
'django.core.context_processors',
因为,看里面django.core
,似乎没有名为的模块context_processors
:
>>> dir(django.template.context_processors)
['SimpleLazyObject', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'csrf', 'debug', 'get_token', 'i18n', 'itertools', 'lazy', 'media', 'request', 'settings', 'static', 'tz']
>>> dir(django.core)
['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', 'cache', 'checks', 'exceptions', 'files', 'mail', 'management', 'paginator', 'serializers', 'signals', 'signing', 'validators']```
推荐阅读
- android - FirebaseMessagingService 创建后立即销毁
- php - Laravel 似乎没有连接控制器方法
- java - Hibernate updateable=false 如果它不为空
- plsql - 我正在尝试将时区 UTC 转换为 asia/calcutta 它显示错误 ORA-01849 小时必须在 1 到 12 之间
- android - 有没有办法以编程方式清除所有缓存文件?
- android - 动态功能模块中的 Resources$NotFoundException - Android
- javascript - 重新加载页面后自动单击按钮
- laravel - 在 vuejs 中下载链接 excel
- kubernetes - 从配置到某个命名空间的 env 文件创建秘密
- amazon-web-services - 如何找出 AWS 安全组阻止了哪些 IP 地址?