这是settings.py文件。如您所见,调试和模板调试都设置为False。但是,如果我尝试触发404错误,我不会得到常规的404错误或我的404.html文件中的错误。它返回的404错误是来自Django的错误:
“您看到此错误,因为您的Django设置文件中有DEBUG = True。将其更改为False,Django将显示标准的404页面。”
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'this is a secret'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
TEMPLATE_DEBUG = False
ALLOWED_HOSTS = ['mywebsite.com','my website\'s ip']
# Application definition
INSTALLED_APPS = (
'myapp',
'django.contrib.admin',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
)
MIDDLEWARE_CLASSES = (
'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 = 'django_project.urls'
WSGI_APPLICATION = 'django_project.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.6/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Internationalization
# https://docs.djangoproject.com/en/1.6/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/1.6/howto/static-files/
STATIC_ROOT = '/home/django/django_project/django_project/static'
STATIC_URL = '/static/'
帮助!
答案 0 :(得分:1)
(只是为了表明这个问题得到了答案 - @ e4c5)
摘要: 如果您的django应用程序作为单独的守护程序(manage.py runfcgi,gunicorn,uwsgi等)运行,每次更改源文件(包括settings.py)时 - 都需要重新启动应用程序
关于模板 - 这取决于你如何加载它们 - 如果你使用任何形式的缓存 - 你应该重新加载守护进程,没有缓存 - 它应该自动重新加载
确保您的日期和时间始终设置正确,有时报告的错误包括在代码升级应用程序仍在运行旧版本之后 - 在大多数情况下日期存在问题 - 已编译的.pyc文件比您的源文件更新部署后的.py个,./manage.py clean_pyc
是一件好事。