【发布时间】:2019-04-15 20:58:40
【问题描述】:
您好,我目前是 Django 新手,我正在尝试填充产品页面。
我在使用 img 来显示图像时遇到问题(它使用在线图像 url 而不是文件),例如 img src="media3.scdn.vn/img2/2018/6_2/ZIBLXA_simg_b5529c_250x250_maxb.jpg"
我的数据库中已经存在带有文本media3.scdn.vn/img2/2018/6_2/ZIBLXA_simg_b5529c_250x250_maxb.jpg的网址
但是当我尝试在模板中渲染它时,图像没有显示 我尝试使用但它仍然无法正常工作 任何帮助将不胜感激!
我的模板
{% for discount in discounts|slice:":8" %}
<div class="col-md-3 product-men women_two">
<div class="product-googles-info googles">
<div class="men-pro-item">
<div class="men-thumb-item">
<img src="{{STATIC_URL}}{{discount.product_image}}" alt=""/>
<div class="men-cart-pro">
<div class="inner-men-cart-pro">
<a href="single .html" class="link-product-add-cart">Quick View</a>
</div>
</div>
<span class="product-new-top">New</span>
</div>
<div class="item-info-product">
<div class="info-product-price">
<div class="grid_meta">
<div class="product_price">
<h4>
<a href="single.html">{{discount.product_name}}</a>
</h4>
<div class="grid-price mt-2">
<span class="money ">{{discount.product_old_price}}</span>
</div>
</div>
<div>
<h3>{{discount.product_sit}}</h3>
</div>
<div><h2 style="color:red">Only {{discount.product_price}}!</h2></div>
</div>
</div>
<div class="clearfix"></div>
</div>
</div>
</div>
</div>
{% endfor %}
编辑
似乎 src 试图获取的图像是“http://127.0.0.1:8000/media3.scdn.vn/img2/2018/6_2/ZIBLXA_simg_b5529c_250x250_maxb.jpg”,我不希望链接中出现“http://127.0.0.1:8000/”。使用 {{discount.product_image}} 标签时有没有办法消除它?
主项目 urls.py:
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('frontend.urls')),
]
前端应用 urls.py:
from django.urls import path
from .import views
from django.conf import settings
from django.conf.urls.static import static
app_name = 'frontend'
urlpatterns = [
#index
path('',views.index, name='index')
]
【问题讨论】: