I just hosted my django application on cpannel, the app was created successfully but i get an ‘error 500 ## Internal Server Error An internal server error has occured.’ when i click the link to my app. I need your help on dealing with this error
here is my settings.py file
"""
Django settings for cl project.
Generated by 'django-admin startproject' using Django 4.2.2.
For more information on this file, see
https://docs.djangoproject.com/en/4.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.2/ref/settings/
"""
from pathlib import Path
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
import mimetypes
mimetypes.add_type("text/css", ".css", True)
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure--ccvlk=czz(nwy+fxys=z8)f^e4na*#7kk2@agna(r%(yduf6f'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
ALLOWED_HOSTS = ['theecl.net','192.168.0.116','127.0.0.1', '127.0.0.1:8000', 'server212.orangehost.com']
STRIPE_PUBLISHABLE_KEY = 'pk_test_51NpZhqBIbtIC9ipbDPHApKDVkQMBuv1CZ6FjRvQEFLxCQZZlvuDgnisaV171AZGPBVkCQeIxzQyBvJ1FWsWEn3Ry000DNvqZHY'
STRIPE_SECRET_KEY = 'sk_test_51NpZhqBIbtIC9ipbCZP9utNF1bwVPbjeMEeM0547li4wqTBeptS717OsADoeAgquS9yuAYQgAAO2cASkPeg24iWs00wY2DCx5p'
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'myapp',
'widget_tweaks',
'store',
]
MESSAGE_STORAGE = 'django.contrib.messages.storage.session.SessionStorage'
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'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 = 'cl.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 = 'cl.wsgi.application'
# Database
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
# Password validation
# https://docs.djangoproject.com/en/4.2/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/4.2/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.2/howto/static-files/
STATIC_URL = '/static/'
STATICFILES_DIRS = [
BASE_DIR / "static",]
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
# Default primary key field type
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
here is my views.py
from pyexpat.errors import messages
from django.shortcuts import redirect, render
from django.http import HttpResponse
from django.contrib import messages
from .forms import AppointmentForm
from .models import *
from django.core.mail import send_mail
from datetime import datetime
from django import forms
from django.core.exceptions import ValidationError
from django.utils.dateparse import parse_date, parse_time
from django.http import HttpResponseRedirect
from django.urls import reverse
from django.http import JsonResponse
# Create your views here.
def home(request):
form = AppointmentForm() # Create an instance of the form
return render(request, 'index.html', {'form': form})
def about(request):
return render(request,'about.html')
def services(request):
return render(request,'services.html')
def pricing(request):
return render(request,'pricing.html')
def contact(request):
return render(request,'contact.html')
def appointment(request):
return render(request, 'appointment.html')
def success_view(request):
return render(request, 'success.html')
def store(request):
return render(request, 'store.html')
def create_appointment(request):
if request.method == 'POST':
form = AppointmentForm(request.POST)
if form.is_valid():
appointment_date = form.cleaned_data['appointment_date']
appointment_time = form.cleaned_data['appointment_time']
# Check if the selected date and time are available
if Appointment.objects.filter(appointment_date=appointment_date, appointment_time=appointment_time).exists():
messages.error(request, 'The selected date and time are not available. Please choose another slot.')
return JsonResponse({'status': 'error', 'message': 'Appointment slot not available'})
form.save()
# Log the form data
print(form.cleaned_data)
messages.success(request, 'Appointment created successfully.')
return JsonResponse({'status': 'success', 'message': 'Appointment created successfully'})
else:
messages.error(request, 'Error submitting the form. Please check the entered data.')
return JsonResponse({'status': 'error', 'message': 'Error submitting the form. Please check the entered data.'})
else:
form = AppointmentForm()
return render(request, 'index.html', {'form': form})
here is my url.py
from django import views
from django.urls import path
from .views import *
urlpatterns = [
path('', home, name='home'),
path('about/', about, name='about'),
path('services/', services, name='services'),
path('pricing/', pricing, name='pricing'),
path('contact/', contact, name='contact'),
path('success/', success_view, name='success_view'),
path('create_appointment/', create_appointment, name='create_appointment'),
]
here is my models.py
from django.db import models
class Appointment(models.Model):
SERVICE_CHOICES = [
('microshading', 'Microshading'),
('eyebrow_waxing', 'Eyebrow Waxing'),
# Add more service choices as needed
]
appointment_date = models.DateTimeField(blank=True, null=True)
appointment_time = models.TimeField()
full_name = models.CharField(max_length=100)
your_email = models.EmailField()
your_phone = models.CharField(max_length=20, null=True)
your_address = models.CharField(max_length=100)
service_type = models.CharField(max_length=20, choices=SERVICE_CHOICES)
message = models.TextField()
def __str__(self):
return self.full_name
here is what shows in my logs