当我尝试给出404 error view
时,我的风格并不起作用。我尝试创建自定义404视图但它也不起作用。
这是我的代码。
settings.py
DEBUG = False
TEMPLATE_DEBUG = DEBUG
ALLOWED_HOSTS = ['*']
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'ran_app/templates')],
'APP_DIRS': True,
'OPTIONS': {
'debug': DEBUG,
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
STATIC_URL = '/static/'
我在模板中也有404.html页面。
这是浏览器错误。
无法加载资源:服务器响应状态为404 (未找到)
答案 0 :(得分:1)
当存在DEBUG = False时,默认的Django包不会提供服务器中的任何静态文件。您必须使用类似nginx的工具来提供文件,这就像生产服务器一样。