为什么我无法使用django在错误页面中导入CSS / JS代码

时间:2016-11-28 18:59:41

标签: python html css django

我在我的django应用程序中出现了一个自定义的error_page,当出现问题时我会调用它。问题是当我尝试加载我的' base.html'或者与javascript,CSS或python代码有关的任何内容我得到的错误如下:

ValueError: The file 'style.css' could not be found with <whitenoise.storage.CompressedManifestStaticFilesStorage object at 0x7ff3b288d9d0>.

这是我的代码:

URLS.PY

from django.conf.urls import handler400, handler403, handler404, handler500

handler500 = main_views.server_error

MAIN_VIEWS.PY

def server_error(request):
    return render (request, 'error_page.html', status=500)

ERROR_PAGE.HTML

{% extends "account/base.html" %}

{% block head_title %}Error Page{% endblock %}

{% block content %}

<script>
setTimeout(function() {
     $.get("{% url 'home_page' %}") // Do something after 5 seconds
}, 5000);
<script/>

<h1><b>AN ERROR OCURRED! THIS PAGE DOESN'T EXISTS OR COULDN'T BE FIND! YOU WILL BE REDIRECTED TO HOME PAGE IN 5 SECONDS...</b></h1>

{% endblock content %}

出了什么问题?

1 个答案:

答案 0 :(得分:0)

在使用python manage.py collectstatic

运行服务器之前,您需要运行DEBUG=False

此外,在您的settins.py中,您应该:

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')