html - 当我在 Django 中使用“扩展”和“阻止”时,我的 CSS 没有出现
问题描述
我花了半天时间试图弄清楚这一点。我最终通过 HTML 样式属性传递了 CSS。我做了什么并尝试过:
- 在settings.py我包括:
django.contrib.staticfiles
STATIC_URL = '/static/'
- 在layout.html中:
{% load static %}
<link href="{% static 'auctions/styles.css' %}" rel="stylesheet">
- 静态文件夹按以下方式组织:
app_name/static/auctions/styles.css 4. 扩展布局和填充body块
- 我试过
{% load static %}
在上面添加; - 我已经把
<link href="{% static 'auctions/styles.css' %}" rel="stylesheet">
之后并重新启动了服务器,但这一切都无济于事;模板:
{% extends "auctions/layout.html" %}
{% load humanize %}
{% load crispy_forms_tags %}
{% block body %}
{% if listing.closed == True %}
<div style="background-color: whitesmoke; height: 110%; width: 100%; position: absolute; opacity: 0.6; z-index: 2;">
<div style="margin-top: 30%; font-size: xxx-large;">
<center>
<strong>
This listing is closed. <br>
<p style="color: green;">{% if request.user == winner.user %} You ({{ winner.user }}) have Won the auction! Congrats! {% endif %}</p>
</strong>
</center>
</div>
</div>
{% endif %}
{% if error_check == True %}
<div class="alert alert-warning" role="alert">
<center>
Your bid is lower than the current bid! Try with a higher one.
</center>
</div>
{% elif error_check == False %}
<div class="alert alert-success" role="alert">
<center>
Your bid was successfully placed!
</center>
</div>
{% endif %}
<div>
<div>
{% if button %}
<form method="POST" action="{% url 'view_list' listing.id %}">
{% csrf_token %}
<input type="hidden" name="close_list" value="True">
<input type="submit" class="btn btn-success" value="Close the Auction">
</form>
{% endif %}
</div>
<div>
{% if not watchlisted or watchlisted.watchlist == False %}
<form method="POST" action="{% url 'view_list' listing.id %}">
{% csrf_token %}
<input type="hidden" name="watchlist_add" value="True">
<input type="submit" class="btn btn-primary" value="Add to Watchlist">
</form>
{% else %}
<form method="POST" action="{% url 'view_list' listing.id %}">
{% csrf_token %}
<input type="hidden" name="watchlist_add" value="False">
<input type="submit" class="btn btn-primary" value="Remove from Watchlist">
</form>
{% endif %}
</div>
<h3>Listing: {{ listing.title }}</h3>
<img src="{{ listing.image }}" alt="Listings' Images">
<p>{{ listing.description }}</p>
{% if not bid %}
<strong>${{ listing.price|stringformat:"1.2f" }}</strong>
{% else %}
<strong>${{ bid|stringformat:"1.2f" }}</strong>
{% endif %}
<p> {{ total_bids }} bid(s) so far. {% if bid_user %} {{ bid_user }} {% endif %}</p>
<form method="POST" name="bidding" action="{% url 'view_list' listing.id %}">
{% csrf_token %}
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text">$</span>
</div>
<div style="margin: 0; padding: 0 2px; height: 6px; z-index: 1;">
{% crispy form %}
</div>
<div class="input-group-append" >
<span class="input-group-text">.00</span>
</div>
<input type="submit" class="btn btn-primary" value="Place Bid">
</div>
</form>
<div style="width: 222;">
<form action="{% url 'view_list' listing.id %}" name="comment" method="POST">
<input type="submit" class="btn btn-secondary btn-sm" value="Comment">
{% crispy comment %}
</form>
<div>
{% for c in comments %}
<ul>{{ c.user }}: {{ c.comment }} {{c.created_at}}</ul>
{% empty %}
No comments yet.
{% endfor %}
</div>
</div>
<h4>Details</h4>
<li>Listed by: {{ listing.user }} </li>
<li>Category: {{ listing.category }} </li>
<li>Listing created at: {{ listing.created_at }} </li>
</div>
{% endblock %}
解决方案
问题出在浏览器上,尤其是缓存...
推荐阅读
- woocommerce - 在 WooCommerce 管理订单页面上显示折扣税详情
- java - 我将如何在不同的行(java)上创建平滑的垂直文本波浪?
- spring-kafka - EmbeddedKafka w/ContainerTestUtils.waitForAssignment 抛出:预期为 1,但得到 0 个分区
- python - 熊猫可以正确处理 datetime.datetime 子类吗?
- amazon-web-services - 使用 Terraform 动态创建多个 WAF 规则
- python - 使用键值修改 Json 文件
- python - Keras/ImageAI 对每张图片进行相同的分类
- python - 如果在 for 循环中找不到 re.findall 匹配项,如何打印?
- sql - 为什么这个 SQL 不起作用?[JD 爱德华兹 DB2]
- c++ - 为什么我尝试使用读写时 fstream 无法正常工作?