【发布时间】:2021-05-28 13:44:06
【问题描述】:
我正在构建一个 BlogApp,但遇到了一个问题。
问题
Static Files 未从 static folder 加载。有些文件正在加载,但有些没有加载。
我做了什么?
urls.py
我也将static url 放在 urls.py 中,它也不适合我。
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
settings.py
os.path.join(BASE_DIR, "static", "static")
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'),
]
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static_cdn')
my_template.html
{% load static %}
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:400,600" />
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Next Level - Gallery</title>
<!--
Next Level CSS Template
https://templatemo.com/tm-532-next-level
-->
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:400,600" />
<script src="{% static 'comments/all.min.css' %}"></script>
<script src="{% static 'comments/bootstrap.min.css' %}"></script>
<script src="{% static 'comments/templatemo-style.css' %}"></script>
</head>
<div class="row tm-welcome-row">
<div class="col-12">
<div
class="tm-welcome-parallax tm-center-child"
data-parallax="scroll"
data-image-src="static/images/blooming-bg.jpg"
>
<div class="tm-bg-black-transparent tm-parallax-overlay">
<h2>Our Gallery</h2>
<p>this is a parallax background image</p>
</div>
</div>
</div>
</div>
<div class="tm-page-col-right">
<div class="tm-gallery" id="tmGallery">
<div class="tm-gallery-item category-1">
<figure class="effect-bubba">
<img
src="static/comments/gallery/gallery-item-01.jpg"
alt="Gallery item"
class="img-fluid"
/>
</figure>
</div>
</div>
</div>
</div>
</section>
<script src="{% static 'comments/jquery.min.js' %}"></script>
<script src="{% static 'coments/parallax.min.js' %}"></script>
<script src="{% static 'comments/imagesloaded.pkgd.min.js' %}"></script>
<script src="{% static 'comments/isotope.pkgd.min.js' %}"></script>
<script src="{% static 'comments/bootstrap.min.js' %}"></script>
<script>
$(function() {
/* Isotope Gallery */
// init isotope
var $gallery = $(".tm-gallery").isotope({
itemSelector: ".tm-gallery-item",
layoutMode: "fitRows"
});
// layout Isotope after each image loads
$gallery.imagesLoaded().progress(function() {
$gallery.isotope("layout");
});
$(".filters-button-group").on("click", "a", function() {
var filterValue = $(this).attr("data-filter");
$gallery.isotope({ filter: filterValue });
console.log("Filter value: " + filterValue);
});
/* Tabs */
$(".tabgroup > div").hide();
$(".tabgroup > div:first-of-type").show();
$(".tabs a").click(function(e) {
e.preventDefault();
var $this = $(this),
tabgroup = "#" + $this.parents(".tabs").data("tabgroup"),
others = $this
.closest("li")
.siblings()
.children("a"),
target = $this.attr("href");
others.removeClass("active");
$this.addClass("active");
// Scroll to tab content (for mobile)
if ($(window).width() < 992) {
$("html, body").animate(
{
scrollTop: $("#tmGallery").offset().top
},
200
);
}
});
});
</script>
</body>
</html>
我尝试了什么
- 我也尝试了
python manage.py collectstatic,它显示0 static files copied to 'D:\myapp\static_cdn', 248 unmodified.
我尝试了很多答案,其中一些人在 urls.py` 中说 add static url 但它不起作用。
我不知道该怎么办
任何帮助将不胜感激
提前致谢
【问题讨论】:
-
STATICFILES_FINDERS设置的值是多少?comments/all.min.css是{{ BASE_DIR }}/static/static吗? -
你好 markwalker,它成功了,我复制了
app目录中的所有静态文件,现在它工作正常 -
提供的答案有效吗?如果是这样,您应该将其标记为已接受
-
这个答案没有帮助,这个答案与我的解决方案无关
-
您应该添加您的解决方案,以便将此问题标记为已解决????
标签: python django static django-urls django-settings