Python 为什么我能';t使用django在错误页面中导入CSS/JS代码
我的django应用程序中有一个自定义错误页面,当出现问题时我会调用该页面。问题是,当我尝试加载我的'base.html'或任何与javascript、CSS或python代码相关的代码时,我会遇到如下错误:Python 为什么我能';t使用django在错误页面中导入CSS/JS代码,python,html,css,django,Python,Html,Css,Django,我的django应用程序中有一个自定义错误页面,当出现问题时我会调用该页面。问题是,当我尝试加载我的'base.html'或任何与javascript、CSS或python代码相关的代码时,我会遇到如下错误: ValueError: The file 'style.css' could not be found with <whitenoise.storage.CompressedManifestStaticFilesStorage object at 0x7ff3b288d9d0>
ValueError: The file 'style.css' could not be found with <whitenoise.storage.CompressedManifestStaticFilesStorage object at 0x7ff3b288d9d0>.
主视图.PY
from django.conf.urls import handler400, handler403, handler404, handler500
handler500 = main_views.server_error
def server_error(request):
return render (request, 'error_page.html', status=500)
错误\u 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 %}
{%extends“account/base.html”%}
{%block head\u title%}错误页{%endblock%}
{%block content%}
setTimeout(函数(){
$.get(“{%url'主页“%}”)//在5秒后执行操作
}, 5000);
发生了一个错误!此页面不存在或找不到!您将在5秒内重定向到主页。。。
{%endblock内容%}
有什么问题吗?在使用
DEBUG=False运行服务器之前,需要运行python manage.py collectstatic
另外,在您的settins.py
中,您应该有:
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
在使用DEBUG=False运行服务器之前,需要运行python manage.py collectstatic
另外,在您的settins.py
中,您应该有:
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
我已经完成了你发布的所有内容,但没有工作。你还有其他建议吗?我已经做了你发布的所有内容,但没有效果。你还有别的建议吗?