【发布时间】:2021-06-29 15:42:22
【问题描述】:
我正在尝试将一些图片从静态文件夹链接到我的 Django 应用程序,但它会在模板目录中创建一个新的静态文件夹。
我的HTML:
{% load static %}
<!DOCTYPE html>
{% extends 'milk_app/base.html' %}
{% load staticfiles %}
{% block title_block %}
Homepage
{% endblock %}
{% block body_block %}
<!-- Home page for Hosts -->
{% if user.userprofile.account == "Host" %}
<div class="container">
<div class="row">
<div class="home_hover_pictures col-4">
<a href="home.php"><img class="img-responsive" src="{% static 'images/listing-property.jpg' %}"></a>
<h4>Create a new listing</h4>
</div>
<div class="home_hover_pictures col-4">
<a href="home.php"><img class="img-responsive" src="{% static 'images/your-properties.jpg' %}"></a>
<h4>Show your rented properties</h4>
</div>
<div class="home_hover_pictures col-4">
<a href="home.php"><img class="img-responsive" src="{% static 'images/scroll-others.jpg' %}"></a>
<h4>Scroll other properties</h4>
</div>
</div>
</div>
<!-- Home page for Tenants (not the beer) -->
{% elif user.userprofile.account == 'Tenant' %}
<!-- Home page for not logged users -->
{% else %}
<br><br>
<section >
<div>
</div>
</section>
{% endif %}
{% endblock %}
我的文件夹如下所示:
1. APP_APP
2. ACTUALAPP
3. STATIC
* images
- the actual images.jpgs
4. TEMPLATES
* creating a new **{% static 'images** folder
- creating a new image here
所以我的 VS 代码在我不想创建的地方创建了一个新文件,同时还创建了一个没有意义的新 .jpg 文件。为什么会这样?
【问题讨论】:
-
请从您的 settings.py 文件中显示所有与静态文件相关的设置
-
也看看这个 q/a stackoverflow.com/questions/66437690/…
标签: html django-templates django-staticfiles