我正在嘗試將 Django 變量連接到img src. 我找到了一個解決方案,但是當我檢查瀏覽器時,該值仍然沒有顯示。順便說一下,我調用的值是dicttype 看起來像這樣 >>>djangoDict輸出:{<foreignModel: ModelValue>: <Product: Item Desc...}我能夠顯示ModelValue使用 2 個花括號,{{ djangoDict }}但是在與地址連接時我不能這樣做。所以這里我的代碼:{% for dd in djangoDict %} {% with 'products/anotherFolder/'|add:dd|add:'/suffix.jpg' as myImg %} <a class="dropdown-item" data-img="{% static myImg %}">{{ dd }}</a> {% endwith %}{% endfor %這是我在檢查元素時得到的:<a class="dropdown-item" data-img="/assets/suffix.jpg">ModelValue</a>我想顯示的內容:<a class="dropdown-item" data-img="/assets/products/anotherFolder/ModelValue/suffix.jpg">ModelValue</a>非常感謝任何愿意提供幫助的人:)
添加回答
舉報
0/150
提交
取消