我刚刚在Centos 7服务器上完成了使用Django 1.11从SQlite切换(或尝试)到Postgresql的工作。
我收到“服务器遇到内部错误或 配置错误,无法完成您的请求。请 联系服务器管理员,root @ localhost ...”
我已经检查了Apache错误日志,但似乎无法弄清错误日志试图告诉我什么。
这是关闭并启动apache后错误日志中的最新消息:
[mpm_prefork:notice] [pid 8653] AH00170: caught SIGWINCH, shutting down gracefully
[core:notice] [pid 16472] SELinux policy enabled; httpd running as context system_u:system_r:httpd_t:s0
[suexec:notice] [pid 16472] AH01232: suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[auth_digest:notice] [pid 16472] AH01757: generating secret for digest authentication ...
[lbmethod_heartbeat:notice] [pid 16472] AH02282: No slotmem from mod_heartmonitor
[mpm_prefork:notice] [pid 16472] AH00163: Apache/2.4.6 (CentOS) mod_wsgi/3.4 Python/2.7.5 configured -- resuming normal operations
[core:notice] [pid 16472] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'
[:error] [pid 16473] mod_wsgi (pid=16473): Target WSGI script '/home/kad/stargate/stargate/wsgi.py' cannot be loaded as Python module.
[:error] [pid 16473] mod_wsgi (pid=16473): Exception occurred processing WSGI script '/home/kad/stargate/stargate/wsgi.py'.
[:error] [pid 16473] Traceback (most recent call last):
[:error] [pid 16473] File "/home/kad/stargate/stargate/wsgi.py", line 16, in <module>
[:error] [pid 16473] application = get_wsgi_application()
[:error] [pid 16473] File "/home/kad/stargate/stargateenv/lib/python3.6/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
[:error] [pid 16473] django.setup(set_prefix=False)
[:error] [pid 16473] File "/home/kad/stargate/stargateenv/lib/python3.6/site-packages/django/__init__.py", line 27, in setup
[:error] [pid 16473] apps.populate(settings.INSTALLED_APPS)
[:error] [pid 16473] File "/home/kad/stargate/stargateenv/lib/python3.6/site-packages/django/apps/registry.py", line 85, in populate
[:error] [pid 16473] app_config = AppConfig.create(entry)
[:error] [pid 16473] File "/home/kad/stargate/stargateenv/lib/python3.6/site-packages/django/apps/config.py", line 120, in create
[:error] [pid 16473] mod = import_module(mod_path)
[:error] [pid 16473] File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module
[:error] [pid 16473] __import__(name)
[:error] [pid 16473] File "/home/kad/stargate/stargateenv/lib/python3.6/site-packages/django/contrib/postgres/apps.py", line 8, in <module>
[:error] [pid 16473] from .signals import register_type_handlers
[:error] [pid 16473] File "/home/kad/stargate/stargateenv/lib/python3.6/site-packages/django/contrib/postgres/signals.py", line 1, in <module>
[:error] [pid 16473] import psycopg2
[:error] [pid 16473] File "/home/kad/stargate/stargateenv/lib/python3.6/site-packages/psycopg2/__init__.py", line 50, in <module>
[:error] [pid 16473] from psycopg2._psycopg import ( # noqa
[:error] [pid 16473] ImportError: No module named _psycopg
[:error] [pid 16473] mod_wsgi (pid=16473): Target WSGI script '/home/kad/stargate/stargate/wsgi.py' cannot be loaded as Python module.
[:error] [pid 16473] mod_wsgi (pid=16473): Exception occurred processing WSGI script '/home/kad/stargate/stargate/wsgi.py'.
[:error] [pid 16473] Traceback (most recent call last):
[:error] [pid 16473] File "/home/kad/stargate/stargate/wsgi.py", line 16, in <module>
[:error] [pid 16473] application = get_wsgi_application()
[:error] [pid 16473] File "/home/kad/stargate/stargateenv/lib/python3.6/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
[:error] [pid 16473] django.setup(set_prefix=False)
[:error] [pid 16473] File "/home/kad/stargate/stargateenv/lib/python3.6/site-packages/django/__init__.py", line 27, in setup
[:error] [pid 16473] apps.populate(settings.INSTALLED_APPS)
[:error] [pid 16473] File "/home/kad/stargate/stargateenv/lib/python3.6/site-packages/django/apps/registry.py", line 78, in populate
[:error] [pid 16473] raise RuntimeError("populate() isn't reentrant")
[:error] [pid 16473] RuntimeError: populate() isn't reentrant
我的django.conf:
Alias /static /home/kad/stargate/landingpage/static
<Directory /home/kad/stargate/landingpage/static>
Require all granted
</Directory>
<Directory /home/kad/stargate/stargate>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess stargate python-path=/home/kad/stargate:/home/kad/stargate/stargateenv/lib/python3.6/site-packages
WSGIProcessGroup stargate
WSGIScriptAlias / /home/kad/stargate/stargate/wsgi.py
这是settings.py的内容:
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) PROJECT_DIR = os.path.dirname(os.path.abspath(__file__))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = '***'
# SECURITY WARNING: don't run with debug turned on in production! DEBUG = False
ALLOWED_HOSTS = ['*']
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.postgres',
'django.contrib.messages',
'django.contrib.staticfiles',
'landingpage',
'django_filters',
'rest_framework', ]
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 = 'stargate.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'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',
],
},
}, ]
WSGI_APPLICATION = 'stargate.wsgi.application'
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/1.11/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'Europe/Berlin'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images) STATICFILES_DIRS = ( os.path.join(BASE_DIR, 'static/'), ) STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(PROJECT_DIR, 'static')
更糟糕的是,切换回Sqlite后,我仍然遇到相同的错误……有人可以帮忙吗?