簡體   English   中英

從隨機數據中獲取正確路徑

[英]Get a correct path from random data

在我的索引頁面上,我有一個圖片庫。 當有人單擊圖像時,它應該在另一個頁面中顯示更多信息和更多照片。 所有這些都使用for循環從 MySQL 數據庫加載。 我無法從我的數據庫中獲取點擊圖像的詳細信息。 它加載所有數據

這個頁面的過程就像一個新聞網站——所有的新聞都是從一個循環中加載的。 如果有人單擊新聞項目,它應該只顯示有關單擊項目的詳細信息。

下面是我的index.html頁面,還有我的urls.pyviews.py源代碼。

我正在使用 Python、Django 和 MySQL; 所有最新版本。

主頁我的圖片庫的源代碼

{% for x in destination %}
<!-- Destination -->
<a href="destination" id="{{x.id}}"><div class="destination item" >
    <div class="destination_image">
        <img src="{{x.img.url}}" alt="">
        {% if x.offer %}
        <div class="spec_offer text-center"><a >Special Offer</a></div>
        {% endif %}
    </div>
    <div class="destination_content">
        <div class="destination_title"><a href="">{{x.name}}</a></div>
        <div class="destination_subtitle"><p>{{x.short_description}}</p></div>
        <div class="destination_price">From ${{x.price}}</div>
    </div>
</div></a>

{% endfor %}
from . import views
from django.urls import path

urlpatterns = [
    path('destination', views.destination, name='destination'),
    path('', views.index, name='index')
]
from django.shortcuts import render
from .models import Destination


def destination(request):
    dest = Destination
    return render(request, 'destination.html', {'sub_destination': dest})

更改<a>標簽的href屬性,嘗試將圖片的參數插入href以在新頁面中打開(可能是圖片的主鍵)。

在新頁面上,只需檢索圖片的信息並將其顯示給客戶端即可。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM