我目前从我的一个基本模板加载的样式表中收到 403 禁止错误。路径看似正确,但服务器不会加载它。
模板base.html
<!DOCTYPE html>
{% load staticfiles %}
{% load static %}
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- BOOTSTRAP -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- GOOGLE FONTS -->
<link href="https://fonts.googleapis.com/css?family=Lato|Open+Sans|Oswald|Raleway|Roboto+Condensed|Roboto:300,400,900" rel="stylesheet">
<!-- NAV BAR CSS -->
<link rel="stylesheet" href="{% static 'static/css/nav_style.css' %}"> <!-- Resource style -->
<script src="http://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script> <!-- Resource jQuery -->
<script src="{% static 'static/js/modernizr.js' %}"></script> <!-- Modernizr -->
<script src="{% static 'static/js/nav_main.js' %}"></script> <!-- Resource Nav -->
</head>
<body>
<div class="container">
{% block body_block %}
{% endblock %}
</div>
</body>
</html>
我的 CSS 看起来像: nav_style.css
.cd-stretchy-nav.edit-content ul a::after {
right: 7px;
background-image: url(../img/stretchy_nav_cd-sprite-3.svg);
}
返回以下错误:
Failed to load resource: the server responded with a status of 403 (Forbidden)
元素文件夹具有以下结构:
myproject
-myapp
-- ...
-myproject
-- settings.py
-- ...
具体设置是针对另一个为我的所有资源提供服务的静态应用程序
所以对于 settings.py 我有一个 BASE_DIR 和一个 REMOTE_DIR
TEMPLATE_DIR = os.path.join(REMOTE_DIR,"static/html")
STATIC_ROOT = REMOTE_DIR
STATIC_DIR = os.path.join(STATIC_ROOT,"static")
STATICFILES_DIRS = [
STATIC_DIR,
...,
]
STATIC_URL = '/static/'
作为我的 REMOTE_DIR 的静态应用程序如下所示:
static_app
--admin
---css
---fonts
---img
---js
--static
---css
----nav_style.css
---fonts
---html
----myapp
-----base.html
---img
----stretchy_nav_cd-sprite-3.svg
---js
--...
最佳答案
目前还没有找到这个问题的正确和简单的答案,最直接的解决方案是将样式表中请求的 Assets (例如背景图像)直接移动到与 css 文件相同的文件夹中,并相应地调整 url。
关于css - django 在背景图像上返回 403 Forbidden,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45549077/