“Django”;500内部服务器错误“;关于生产中的登录尝试

“Django”;500内部服务器错误“;关于生产中的登录尝试,django,python-3.x,apache2,Django,Python 3.x,Apache2,我是django和web设计的新手,但我有一个运行在raspberry pi上的小型apache2 web服务器,我已经成功地将服务器设置为与django 2.2一起工作,我可以通过dataplicity虫洞访问该网站,该网站将正确加载。然而,当我试图通过dataplicity托管的站点(管理页面或网站)登录时,我得到一个“500-内部服务器错误” apache错误日志中没有任何内容,如果我通过python manage.py运行服务器,runserverlogin只有在通过apache运行时才

我是django和web设计的新手,但我有一个运行在raspberry pi上的小型apache2 web服务器,我已经成功地将服务器设置为与django 2.2一起工作,我可以通过dataplicity虫洞访问该网站,该网站将正确加载。然而,当我试图通过dataplicity托管的站点(管理页面或网站)登录时,我得到一个“500-内部服务器错误”

apache错误日志中没有任何内容,如果我通过
python manage.py运行服务器,runserver
login只有在通过apache运行时才能正常工作,那么我就会遇到问题

这是我的apache2.conf:


DefaultRuntimeDir ${APACHE_RUN_DIR}

PidFile ${APACHE_PID_FILE}

Timeout 300

KeepAlive On

MaxKeepAliveRequests 100

KeepAliveTimeout 5

User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}

HostnameLookups Off

ErrorLog ${APACHE_LOG_DIR}/error.log

LogLevel warn

IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf

Include ports.conf

<Directory />
    Options FollowSymLinks
    AllowOverride None
    Require all denied
</Directory>

<Directory /usr/share>
    AllowOverride None
    Require all granted
</Directory>

<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>

WSGIScriptAlias / /home/pi/pi_site/pi_website/wsgi.py
WSGIPythonHome /home/pi/pi_site/myvenv
WSGIPythonPath /home/pi/pi_site

<Directory /home/pi/pi_site/pi_website>
    <Files wsgi.py>
        Require all granted
    </Files>
</Directory>

Alias /static/ /home/pi/pi_site/static/

<Directory /home/pi/pi_site/static>
    Require all granted
</Directory>

AccessFileName .htaccess

<FilesMatch "^\.ht">
    Require all denied
</FilesMatch>

LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

IncludeOptional conf-enabled/*.conf

IncludeOptional sites-enabled/*.conf
编辑: 我已尝试设置
允许的\u HOSTS=[“*”]
,但这并没有影响500消息。我还尝试删除并重新迁移数据库,创建了一个新的超级用户,但仍然没有效果

编辑-2
我只在登录时收到500条消息,并且只有使用了正确的密码,如果我使用了错误的登录/密码,页面才会正确响应

检查数据库文件的文件权限。也许Apache没有写入它的权限。这将允许只需要读取但需要登录才能写入数据库的页面。当通过runserver运行它时,它将以您的用户身份访问该文件,因此权限可以确定。

那么,您可以通过本地主机和dataplicity登录到您的站点,但不能在其他主机上登录?对吗?如果是这种情况,您可能需要将不同的主机添加到settings.py文件中允许的_HOSTS中。@rob no当我运行
python manage.py runserver
时,我可以使用127.0.0.1:8000登录,但当我试图在其运行dataplicity/apache时,我会得到500个errortry
ALLOWED_HOSTS=['*']
只是为了尝试消除causes@PercivalRapha不,我只是在尝试登录到Clearify后遇到了相同的500错误,是否有不需要登录的页面工作正常,只是登录有问题?此外,您的设置具有
DEBUG=True
,因此大多数500个错误都会显示一些调试信息。我猜你没有看到什么?
import os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

SECRET_KEY = '*******'

DEBUG = True

ALLOWED_HOSTS = [".dataplicity.io", "127.0.0.1"]


INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'main_site',
]

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 = 'pi_website.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 = 'pi_website.wsgi.application'


DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}


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',
    },
]

LOGIN_REDIRECT_URL = '/'

LANGUAGE_CODE = 'en-uk'

TIME_ZONE = "UTC"

USE_I18N = True

USE_L10N = True

USE_TZ = True

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')