【问题标题】:Django 1.11 (Python 3.+) doesn't work styles, when I make DEBUG=False当我设置 DEBUG=False 时,Django 1.11 (Python 3.+) 无法正常工作
【发布时间】:2017-12-12 19:11:56
【问题描述】:

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

【问题讨论】:

标签: django-1.11


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2020-09-03
    • 2017-08-13
    • 1970-01-01
    • 2011-05-25
    • 2016-01-19
    • 2013-12-03
    • 2021-08-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多