shop.html
{% extends 'base.html' %}
{% block content %}
<div class="container">
<!-- Product List -->
<br>
<h2 align="center">List of Products</h2>
<br>
<div class="row">
{% for product in products %}
<div class="col-3 col-md-3 col-sm-3">
<div class="card">
<form method="POST" action="{% url 'add_to_cart' product.id %}">
{% csrf_token %}
<img src="{{ product.image.url }}" class="card-img-top" alt="...">
<div class="card-body">
<h5 name="item" class="card-title">{{product.name}}</h5>
<div class="card-text">
<p>Category: {{ product.category }}</p>
<p>Price:</p>
<p style="text-decoration: line-through;color:red;">{{ product.price }}</p>
<p style="color:blue;">{{ product.discount_price }}</p>
</div>
<hr>
<input name="quantity" type="number" value="1">
<input type="submit" class="btn btn-primary" value="Add to Cart">
</form>
</div>
</div>
{% endfor %}
</div>
</div>
{% endblock %}
base.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Online Shopping System</title>
<!-- CSS only -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-KyZXEAg3QhqLMpG8r+8fhAXLRk2vvoC2f3B09zVXn8CA5QIVfZOJ3BCsw2P0p/We" crossorigin="anonymous">
</head>
<body>
{% include 'navbar.html' %}
{% block content %} {% endblock %}
<!-- JavaScript Bundle with Popper -->
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
<!-- -->
</body>
</html>
对于此代码,我使用了该类col-3
,并且第二个产品仍然放在第一个产品下。相反,我想把第二张产品卡放在第一张旁边。我从 Bootstrap Card Grid System 中获取了代码,但即使我已将所需的引导 css 和 javascript 链接放入base.html
. 我可以问我需要改变什么才能让卡片连续 3 次吗?