当前位置: 首页 > 面试题库 >

设置DEBUG = False会导致500错误

齐甫
2023-03-14
问题内容

有一次,我改变DEBUG = False,我的网站将产生500(使用WSGI和manage.py runserver命令),并且在Apache的错误日志中没有错误信息,当我改变它通常会运行debug到True。

我正在使用Django 1.5和Python 2.7.3,这是Apache访问日志,并且在apache错误日志中没有任何日志

www.beta800.net:80 222.247.56.11 - - [28/Feb/2013:13:42:28 +0800] "GET / HTTP/1.1" 500 257 "-" "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.97 Safari/537.22"
www.beta800.net:80 222.247.56.11 - - [28/Feb/2013:13:42:28 +0800] "GET /favicon.ico HTTP/1.1" 500 257 "-" "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.97 Safari/537.22"
www.beta800.net:80 222.247.56.11 - - [28/Feb/2013:13:42:28 +0800] "GET /favicon.ico HTTP/1.1" 500 257 "-" "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.97 Safari/537.22"

这是我的设置文件:

import os.path    
DEBUG = False 
#TEMPLATE_DEBUG = DEBUG

HERE = os.path.dirname(__file__)
ADMINS = (
    ('admin', 'xyzadmin@qq.com'),
)

MANAGERS = ADMINS

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'zdm',                      # Or path to database file if using sqlite3.
        'USER': 'root',                      # Not used with sqlite3.
        'PASSWORD': 'passwd',                  # Not used with sqlite3.
        'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
    }
}

# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# In a Windows environment this must be set to your system time zone.
TIME_ZONE = 'America/Chicago'

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'

SITE_ID = 1

# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True

# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale.
USE_L10N = True

# If you set this to False, Django will not use timezone-aware datetimes.
USE_TZ = True

# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
MEDIA_ROOT = ''

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
MEDIA_URL = ''

# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
#STATIC_ROOT = os.path.join(HERE, 'static').replace('\\','/')

# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'
#STATIC_ROOT = os.path.join(HERE, 'static').replace('\\','/')
S= os.path.join(HERE, 'static').replace('\\','/')

# Additional locations of static files
STATICFILES_DIRS = (
    # Put strings here, like "/home/html/static" or "C:/www/django/static".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
    '/home/zdm/static',
)

# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
#    'django.contrib.staticfiles.finders.DefaultStorageFinder',
)

# Make this unique, and don't share it with anybody.
SECRET_KEY = '9a7!^gp8ojyk-^^d@*whuw!0rml+r+uaie4ur$(do9zz_6!hy0'

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
#     'django.template.loaders.eggs.Loader',
)

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    # Uncomment the next line for simple clickjacking protection:
    # 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

ROOT_URLCONF = 'zdm.urls'

# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'zdm.wsgi.application'

TEMPLATE_DIRS = (
    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
    '/home/zdm/templates',
)

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # Uncomment the next line to enable the admin:
    'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    # 'django.contrib.admindocs',
    'zdm',
    'portal',
    'admin',
    'tagging',
)

问题答案:

Django 1.5引入了出于安全原因所需的允许主机设置。使用Django 1.5创建的设置文件具有此新部分,您需要添加该部分:

See https://docs.djangoproject.com/en/1.9/ref/settings/#allowed-hosts

ALLOWED_HOSTS = []
在此处添加主机['www.beta800.net‘]或[‘‘]进行快速测试,但不要[‘‘]用于生产。



 类似资料:
  • 我正在Docker容器中运行我的Django应用程序,其中nginx作为Web服务器,uWSGI作为应用程序服务器。一切都部署在AWS Elastic Beanstalk上。当我设置DEBUG=False时,所有的请求都会导致错误的请求(400)。我尝试了两个和,但仍然出现相同的错误。我通过检查日志来验证请求是否到达uWSGI。uWSGI日志包含以下内容: 我试过很多答案,但都不走运。我试过这个答

  • 问题内容: 使用开发服务器,它可以与debug = True或False一起使用。 在生产中,如果debug = True,一切正常,但是如果debug = True,则出现500错误,并且apache日志以导入错误结尾:“ ImportError:无法导入名称Project”。 导入中的任何操作都不会对调试产生任何条件-唯一执行的代码是开发服务器是否应提供静态文件(在生产中,apache应该处理

  • 我有个例外 2018-11-01 21:05:49.122错误31446---[nio-8080-exec-1]O.A.C.C.C.[.[.[/].[dispatcherServlet]:servlet.Service()在路径[]上下文中的servlet[dispatcherServlet]引发异常[请求处理失败;嵌套异常为org.springframework.web.multipart.ma

  • 问题内容: 我正在使用Django作为我的主力构建应用程序。到目前为止,一切都很好-指定了数据库设置,配置的静态目录,URL,视图等。但是,当我想呈现自己漂亮的自定义404.html和500.html页面时,麻烦开始悄悄出现。 我阅读了有关自定义错误处理的文档,并在UrlsConf中设置了必要的配置,创建了相应的视图,并将404.html和500.html添加到了我的应用程序的模板目录(也在set

  • 当我的DEBUG=False时显示“错误:-1”,当我的DEBUG=True时显示“错误:-2”。 我将使用python 3.7.7和django 3.0.4。 我的设置。py文件是:- 这是“错误:1”。。。。[调试=False时] 这是“错误:-2”。。。[调试=True时] 但是在'DEBUG=True'的时候,我的管理页面是打开的,但它在终端中给出了下面的错误。 当我试图在浏览器中打开“/

  • 问题内容: 因此,当我在web.config中设置maxJsonLength时,在我的.net站点上一直显示500-Internal server error页面。 我正在修改.config,因为即使我在vb.net JavaScriptSerializer上使用MaxJsonLength = Int32.MaxValue,我仍然要为大型词典获取InvalidOperationException,