亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

無法從 /media/ 文件夾中獲取圖像,如果我嘗試通過它的索引訪問

無法從 /media/ 文件夾中獲取圖像,如果我嘗試通過它的索引訪問

子衿沉夜 2022-12-06 16:14:12
這是我的設置.py靜止的STATIC_URL = '/static/'STATIC_DIR = [os.path.join(BASE_DIR, "static")]媒體MEDIA_ROOT = os.path.join(BASE_DIR, 'media')MEDIA_URL = '/media/'URL 代碼 - urls.pyfrom django.urls import pathfrom . import viewsurlpatterns = [path("", views.index, name="ShopHome"),視圖代碼 - views.py輸入from django.shortcuts import renderfrom . models import Productfrom math import ceil試圖使滑塊顯示 4 個產品(一次)并遍歷數據庫中的產品列表def index(request):        products = Product.objects.all()        print(products)        n = len(products)        nSlides = n//4 + ceil((n/4)-(n//4))        params = {'no_of_slides':nSlides, 'range': range(1, nSlides), 'product': products}        return render(request, 'shop/shop.html', params)模板代碼 - shop.html{% load static %}這工作正常。    <div class="central-meta">    <span class="create-post">Robotic Products <a href="#" title="">See All</a></span>        <ul class="suggested-frnd-caro">          <li>            <img src="/media/{{product.0.image}}">               <div class="sugtd-frnd-meta">                   <a href="#" title="">{{product.0.product_name}}</a>                    <span>2 mutual friend</span>                    <ul class="add-remove-frnd">                       <li class="add-tofrndlist"><a href="#" title="Add friend"><i class="fa fa-star"></i></a></li>                       <li class="remove-frnd send-mesg"><a href="#" title="remove friend"><i class="fa fa-comment"></i></a></li>                     </ul>                </div>                       </li>但在這里我有問題無法遍歷要顯示的產品列表
查看完整描述

1 回答

?
守候你守候我

TA貢獻1802條經驗 獲得超10個贊

       {% for i in product|slice:"1:"%}

                <li>

                    <img src="{{ i.img }}"> 

<!--But in models.p at class  product field img exist !!     -->

                    <div class="sugtd-frnd-meta">

                        <a href="#" title="">{{product.i.product_name}}</a> <!-- fetching from DB -->

                        <span>2 mutual friend</span>

                        <ul class="add-remove-frnd">

                            <li class="add-tofrndlist"><a href="#" title="Add friend"><i class="fa fa-star"></i></a></li>

                            <li class="remove-frnd send-mesg"><a href="#" title="remove friend"><i class="fa fa-comment"></i></a></li>

                        </ul>

                    </div>

            {% endfor %}

                </li>

            </ul>

      </div>

  </div>


查看完整回答
反對 回復 2022-12-06
  • 1 回答
  • 0 關注
  • 100 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號