简体   繁体   中英

Get a correct path from random data

On my index page, I have an image gallery. When someone clicks on an image, it should show more information with more photos in another page. All are loading from MySQL database using a for loop. I'm unable to get the detail of clicked image from my data base. It loads all the data

This page's process is like a news website -- all the news loading from a loop. if someone clicks on a news item it should only show details about the clicked item.

Below is my index.html page, my urls.py and views.py source code also.

I'm using Python, Django with MySQL; all latest versions.

Home page , source code of my images gallery

{% 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})

Change the href attribute of <a> tag, try to insert the parameter of the image into href to open in new page (maybe the primary key of image).

On the new page, just retrieve the information of the picture and show it to the client.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM