我有一个 django 项目,我用它来创建库存管理系统。我有一个 html 网站,其中显示产品说明。它还应该显示由代码生成的条形码图像。您可以看到程序生成的条形码图像,但无法在网页中查看它,除非您通过转到保存图像的文件手动打开。
<!-- inventory/product_detail.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ product.name }}</title>
</head>
<body>
<h1>{{ product.name }}</h1>
<p>Barcode:</p>
<img src="{{ product.barcode_image.url|default:'#' }}" alt="Barcode Image">
<!-- Use product.barcode_image.url to get the URL of the barcode image -->
<p>Barcode Image URL: {{ product.barcode_image.url }}</p>
<p>Quantity: {{ product.quantity }}</p>
<p>Price: ${{ product.price }}</p>
<a href="{% url 'product_list' %}">Back to Product List</a>
</body>
</html>
这是产品详细信息页面。我希望页面显示由我的 django 代码生成的条形码图像。
将图像保存在“存储 HTML 文件”的“同一文件”中,并在 img scr 中写入带有扩展名的图像名称。这可能对你有帮助。