I am having a little project and am trying to set up a website using Django, Apache 2 and mod_wsgi. Everything runs fine in the Django development server, and I can also open the front page of my site using apache.
However, when I try to log in into the admin page, or use my own custom log in page, I get a Server error (500). Can anyone tell me what I am doing wrong?
settings.py:
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SECRET_KEY = ...
DEBUG = True
ALLOWED_HOSTS = ["localhost", "192.168.0.121", "127.0.0.1"]
LOGIN_REDIRECT_URL='/account'
LOGOUT_REDIRECT_URL='/login'
INSTALLED_APPS = [
'account.apps.AccountConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
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 = 'kraken.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',
],
},
},
]
WSGI_APPLICATION = 'kraken.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',
},
]
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "static/")
000-default.conf:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
Alias /static /home/pi/kraken/static
Alias /favicon.ico /home/pi/kraken/static/favicon.ico
<Directory /home/pi/kraken/static>
Require all granted
</Directory>
<Directory /home/pi/kraken/kraken>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess kraken python-path=/home/pi/kraken python-home=/home/pi/.conda/envs/django
WSGIProcessGroup kraken
WSGIScriptAlias / /home/pi/kraken/kraken/wsgi.py
</VirtualHost>
I used chown:www-data on my database and my project folder
I followed Graham Dumpleton's advice and found that the permissions on my database weren't sufficient. I fixed that using chown www-data db.sqlite3
, and my problem was solved.
This happened with me due to DEBUG = False
Check https://docs.djangoproject.com/en/3.0/howto/error-reporting/
Django Documentation cleared the Issue.
If you are trying to run your web app on a live server then you must update this field in the settings.py file.
ALLOWED_HOSTS = ["localhost", "192.168.0.121", "127.0.0.1"]
This must include the IP address of your web server, otherwise Django will raise a 500 server error like the one you are encountering.
检查您的数据库文件的权限。
I solved it, my url file had a {} brackets chagned it to [] under urlpatterns
urlpatterns = [
path('admin/', admin.site.urls),
]
And it resolved it
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.