2

当我尝试它时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(未找到)

4

1 回答 1

1

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

于 2017-07-08T16:51:46.547 回答