简体   繁体   English

当 DEBUG=False 时,我的 Django 管理面板给出服务器错误(500)

[英]My Django admin panel gives server error(500) when DEBUG=False

"Error:-1" is show when my DEBUG=False and "Error:-2" is show when my DEBUG=True.当我的 DEBUG=False 时显示“错误:-1”,当我的 DEBUG=True 时显示“错误:-2”。

I will use python 3.7.7 and django 3.0.4 .我将使用python 3.7.7django 3.0.4

my settings.py file is:-我的 settings.py 文件是:-



DEBUG = False

ALLOWED_HOSTS = ["*"] 

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'home.apps.HomeConfig',
]

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 = '***************'

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 = '*************************'


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

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}


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

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
#

#for uploaded image

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

#end of uploded image


STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'static'),
    # '/static/',
]

This is " Error:1 ".... [ When DEBUG=False ]这是“错误:1 ”.... [当 DEBUG=False 时]


[15/Mar/2020 11:14:56] "GET /admin/login/?next=/admin/ HTTP/1.1" 500 4712
[15/Mar/2020 11:14:56] "GET /static/js/jquery-3.2.1.min.js HTTP/1.1" 304 0
[15/Mar/2020 11:14:56] "GET /admin/login/js/main2.js HTTP/1.1" 404 21440
[15/Mar/2020 11:14:56] "GET /static/js/bootstrap.min.js HTTP/1.1" 304 0
[15/Mar/2020 11:14:56] "GET /admin/login/js/main.js HTTP/1.1" 404 21440
[15/Mar/2020 11:14:56] "GET /static/js/owl.carousel.min.js HTTP/1.1" 304 0
[15/Mar/2020 11:14:56] "GET /static/js/jquery.marquee.min.js HTTP/1.1" 304 0
[15/Mar/2020 11:14:56] "GET /static/js/main.js HTTP/1.1" 304 0
[15/Mar/2020 11:14:56] "GET /admin/login/js/main.js HTTP/1.1" 404 21440

This is " Error:-2 "... [ When DEBUG=True ]这是“错误:-2 ”... [当 DEBUG=True 时]

But at time of ' DEBUG=True ' my admin page is open but it gives below error in terminal.但是在“ DEBUG=True ”时,我的管理页面是打开的,但它在终端中给出了以下错误。

[15/Mar/2020 11:15:51] "GET /admin/login/?next=/admin/ HTTP/1.1" 200 1913

When ever i try to open '/admin/' in my browser i will gives an error, But my home page [ 127.0.0.1:8000 ] it's working properly.当我尝试在浏览器中打开“/admin/”时,我会报错,但我的主页 [127.0.0.1:8000] 工作正常。

thanks in advance.提前致谢。

**Finally error can solve ..** **最后错误可以解决..**

we can remove only three line from settings.py我们只能从 settings.py 中删除三行

1> django_heroku.settings(locals()) this line is require for deployment Django app on Heroku. 1> django_heroku.settings(locals())这一行是在 Heroku 上部署 Django 应用程序所必需的。

2> STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' 2> STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

3> MIDDLEWARE = [ ... 'whitenoise.middleware.WhiteNoiseMiddleware', ] 3> MIDDLEWARE = [ ... 'whitenoise.middleware.WhiteNoiseMiddleware', ]

2nd and 3rd line are use for serve static files on website when DEBUG=False.当 DEBUG=False 时,第 2 行和第 3 行用于在网站上提供静态文件。

after removing this three line error can solve and, It will run perfectly without any error.去掉这三行错误后就可以解决了,运行完美,没有任何错误。

thank you and special thank you for Alasdair .谢谢你,特别感谢Alasdair

Solution解决方案

I had this problem recently.我最近遇到了这个问题。 You have to remove你必须删除

STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

and replace it with并将其替换为

STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.StaticFilesStorage'

I hope I have solved your problem我希望我已经解决了你的问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当 DEBUG=False 时 django 服务器错误 (500) - django server error (500) when DEBUG=False 每当django中debug = False时,Heroku会显示Server Error(500),而debug = True no error时 - Whenever debug=False in django, Heroku gives Server Error (500) and when debug=True no error 当 django 中的 Debug = False 时,为什么我在我的网站上看到服务器错误 500 - Why i am see server error 500 in my website when Debug = False in django 使用 Heroku 和 Django 时 Debug=False 时出现 500 错误 - 500 error when Debug=False with Heroku and Django Django 只有当 500.html 存在时 Debug 为 False 时,国际化才会给出内部错误 - Django Internationalization gives Internal Error when Debug is False Only when 500.html is present 当生产中的debug = False时500服务器错误 - 500 server error when debug=False in production 当 DEBUG=False 时服务器错误 500 - Server Error 500 when DEBUG=False 当 debug 设置为 False 时,在 Heroku 上部署 Django 时出现服务器错误 500 - Server error 500 on Django when deployed on Heroku when debug is set to False 将Debug更改为False后,Django Server Error 500 - Django Server Error 500 after changing Debug to False 尝试在 heroku 上使用 DEBUG=False 部署 django 应用程序时出现服务器错误 (500) - Server error (500) when trying to deploy django app with DEBUG=False on heroku
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM