首页 > 解决方案 > Django admin Page 404 Not Found & 错误处理页面不工作(DEBUG_PROPAGATE_EXCEPTIONS)

问题描述

我的Django项目在本地 PC部署后完美运行

请帮我修复!

我面临一些问题:

  1. 不显示 Django 错误处理页面。
  2. Django 管理页面未显示。

我的设置 & 网址 & 输出文件 在这里,我看不到我的 Django 默认设置,就像我的开发一样。

urls.py 文件

 from django.contrib import admin
    from django.urls import path, include
    from django.conf import settings
    from django.conf.urls.static import static
    
    urlpatterns = [
        
        path('', include('frontend.urls')),
        path('admin/', admin.site.urls),
        #path('admission/', include('admission.urls')),
        path('user/', include('userregistration.urls')),
        path('study/', include('study.urls')),
        path('employment/', include('employment.urls')),
        #path('form/', include('form.urls')),
        
    ]
    
    urlpatterns = urlpatterns + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
    
    admin.site.index_title = "GSL Adminstrator"
    admin.site.index_header = "Global Star Admin"
    admin.site.site_title = "Global Star Admin"
    admin.site.site_header = "Global Star Admin"

设置.py 文件

from pathlib import Path, os

# 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/3.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'wy7o_s_pw$(71l-ta)0w1fud#7%zm3$5^n2p4ygo$an0n)ieqi'

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


ALLOWED_HOSTS = ['dev.globalstar.com.bd', 'www.dev.globalstar.com.bd']


# Application definition

INSTALLED_APPS = [
    'phonenumber_field',
    'dal',
    'dal_select2',
    # 'grappelli',
    'widget_tweaks',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    #'admission',
    'employment',
    #'form',
    'frontend',
    'study', 
    'travel',
    'hrm',
    'event',
    'dal_queryset_sequence',

]

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 = 'gsl.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [
                os.path.join(BASE_DIR, 'frontend/templates'),
                os.path.join(BASE_DIR, 'userregistration/templates'),
                os.path.join(BASE_DIR, 'study/templates'),
                os.path.join(BASE_DIR, 'admission/templates'),
                os.path.join(BASE_DIR, 'employment/templates'), 
                os.path.join(BASE_DIR, 'form/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 = 'gsl.wsgi.application'


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

DATABASES = {
    'default': {
        #'ENGINE': 'django.db.backends.sqlite3',
        #'NAME': BASE_DIR / 'db.sqlite3',
        
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'globalv5_web_app',
        'USER': 'globalv5_gsl_web_app',
        'PASSWORD': 'ky*5q0i3f32U',
        'HOST': 'localhost',
        'PORT': '3306',
    }
}


# Password validation
# https://docs.djangoproject.com/en/3.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/3.1/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/

STATIC_URL = '/static/'


STATICFILES_DIRS =[
    os.path.join(BASE_DIR,'userregistration/static'),
    os.path.join(BASE_DIR,'study/static'),
    os.path.join(BASE_DIR,'employment/static'),
    os.path.join(BASE_DIR,'form/static'),
    os.path.join(BASE_DIR,'admission/static'),
    '/home/globalv5/dev.globalstar.com.bd/public/static',
    
]



STATIC_ROOT = os.path.join(BASE_DIR,'static')
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR,'media')



X_FRAME_OPTIONS = 'ALLOWALL'

XS_SHARING_ALLOWED_METHODS = ['POST','GET','OPTIONS', 'PUT', 'DELETE']

和 python manage.py shell

Python 3.8.6 (default, Dec 10 2020, 03:32:48)
[GCC 7.3.1 20180303 (Red Hat 7.3.1-5)] on linux
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from django.conf import settings
>>> settings.DEBUG
True
>>> settings.DEBUG_PROPAGATE_EXCEPTIONS
False

标签: pythondjangodjango-admindjango-settingsdjango-apps

解决方案


推荐阅读