Django 1.11 (Python 3.+) 不工作风格,当我使 DEBUG=False



当我尝试它时,它会给出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 (未找到(

当有 DEBUG = False 时,默认的 Django 包不会从你的服务器提供任何静态文件。您必须使用类似nginx的工具来提供文件,这是一个类似于生产服务器的条件。

最新更新