404 error on Python App deployment on CPanel

Python==3.11.11 (server ver) Django==5.1.1

Hello, today I was to deploy my app on CPanel, and everything goes fine until the end, because when configurations are all done, the page put an 404 error:

Not Found
The requested URL was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to 
handle the request.

I create the app. Make the MySQL database, do migrations just fine. Also changes some configurations on database, allow_hosts and static root in setting.py:

from pathlib import Path
import os, os.path
# import dj_database_url

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ.get('SECRET_KEY', default='your secret key')

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False

#ALLOWED_HOSTS = []
ALLOWED_HOSTS = ['https://sistema.juanjoserondon.com','sistema.juanjoserondon.com','www.sistema.juanjoserondon.com']

NPM_BIN_PATH = "C:/Program Files/nodejs/npm.cmd" 

INTERNAL_IPS = [
    "127.0.0.1",
]

TAILWIND_APP_NAME = 'theme'

# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django_browser_reload',
    'phonenumber_field',
    'tailwind',
    'theme',
    'main',
    'dashboard',
    'billing',
    'teaching',
]

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',
    'django_browser_reload.middleware.BrowserReloadMiddleware',
]

SESSION_ENGINE = 'django.contrib.sessions.backends.db'

ROOT_URLCONF = 'djangocrud.urls'

PROJECT_PATH = os.path.realpath(os.path.dirname(__file__))

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': os.path.join(PROJECT_PATH, '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 = 'djangocrud.wsgi.application'


# Database
# https://docs.djangoproject.com/en/5.1/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'detodit1_sistema_juanjoserondon_db',
        'USER': 'detodit1_kdisell',
        'PASSWORD': 'juanjoserondon_sys',
        'HOST': 'localhost',
        'PORT': '3306',
    }
}


# Password validation
# https://docs.djangoproject.com/en/5.1/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/5.1/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/5.1/howto/static-files/

STATIC_URL = 'static/'
MEDIA_URL='/media/'

# This production code might break development mode, so we check whether we're in DEBUG mode
if not DEBUG:
    #STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
    STATICFILES_DIRS = (os.path.join(BASE_DIR, 'staticfiles'),) 
    STATIC_ROOT='/home/detodit1/public_html/sistema.juanjoserondon.com/static'
    STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
    MEDIA_ROOT='/home/detodit1/public_html/sistema.juanjoserondon.com/media'

# Default primary key field type
# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

AUTH_USER_MODEL='dashboard.CustomUser'

This is djangocrud.urls:

from django.contrib import admin
from django.urls import include, path

urlpatterns = [
    path('__reload__/', include('django_browser_reload.urls')),
    path('admin/', admin.site.urls),
    path('', include('main.urls')),
    path('auth/', include('dashboard.urls')),
    path('auth/', include('billing.urls')),
    path('auth/', include('teaching.urls')),

And this is dashboard.urls:

from django.urls import path
from .views import dashboard_admins, dashboard_teachers, dashboard_students, teachers, students, subjects, schedules, edit

urlpatterns = [
    path('dashboard-admins', dashboard_admins, name='dashboard-admins'),
    path('dashboard-teachers', dashboard_teachers, name='dashboard-teachers'),
    path('dashboard-students', dashboard_students, name='dashboard-students'),
    path('teachers', teachers, name='teachers'),
    path('students', students, name='students'),
    path('subjects', subjects, name='subjects'),
    path('schedules', schedules, name='schedules'),
    path('edit', edit, name='edit'),
]

For default, the server guides the user to …/auth/dashboard-admins, if the user is not login, then redirect to login page. But login page doesn’t work either. I try to change the path, to put it on djangocrud.urls file but nothing change.

My views.py:

from django.shortcuts import redirect, render
from .models import CustomUser, Teachers, Students, Guardians, Subjects, Courses, Sections, Schedules, Tuition, SchoolPeriod

# Create your views here.
# Some variables here...

def auth_user(request) -> bool:
    if request.user.is_authenticated:
        # Do something for authenticated users.
        return True
    else:
        return False


def dashboard_admins(request):
    if auth_user(request) == True:
        # Here are data to save on db
        # ...
        if request.method == 'GET':
            s_count =  s_user.count()
            return render(request, 'dashboard_admins.html',{
                'scounts': s_count,
                'tuser': t_user,
                'suser': s_user,
            })
        else:
            try:
                Subjects.objects.bulk_create(subj_list)
                Sections.objects.bulk_create(sect_list)
                Courses.objects.bulk_create(cour_list)
                SchoolPeriod.objects.create(period='2024-2025').save()
                print('Datos creados')
                return redirect('/auth/dashboard-admins')
            except:
                print('Fallo en la creacion de datos')
                return redirect('/auth/dashboard-admins')
    else:
        return redirect('../login')

from dashboard.views import dashboard_admins

login view:

# Create your views here.
def home(request):
    # return render(request, 'pages/login.html')
    return redirect(dashboard_admins)

def log_in(request):
    if request.method == 'GET':
        return render(request, 'pages/login.html')
    else:
        user = emailBackend.authenticate(request, username=request.POST.get('email'), password=request.POST.get('password'))

        if user != None:
            login(request, user)
            return redirect(dashboard_admins)
        else:
            return HttpResponse('Login invalido')


def log_out(request):
    logout(request)
    return redirect(home)

If someone can give me a hand, I will appreciate.

This are my folders:

Files tree

And I refers to wsgi.py file on the passenger_wsgi.py file:

from djangocrud.wsgi import application

If you need more information, please let me know. The app was working on localhost until today that I try to put it on a server.

Вернуться на верх