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
When DEBUG is False , Django will email the users listed in the ADMINS setting whenever your code raises an unhandled exception and results in an internal server error (strictly speaking, for any response with an HTTP status code of 500 or greater). This gives the administrators immediate notification of any errors.
'django-admin' is not recognized as an internal or external command, operable program or batch file. To fix this, first close the terminal window and relaunch it with administrator privileges. Once you launch the elevated terminal window change directory to where you wish to start your Django project.
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 love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With