[英]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.所有这些都使用
for
循环从 MySQL 数据库加载。 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.下面是我的
index.html
页面,还有我的urls.py
和views.py
源代码。
I'm using Python, Django with MySQL;我正在使用 Python、Django 和 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).更改
<a>
标签的href属性,尝试将图片的参数插入href以在新页面中打开(可能是图片的主键)。
On the new page, just retrieve the information of the picture and show it to the client.在新页面上,只需检索图片的信息并将其显示给客户端即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.