大家好,当我单击标题按钮时,我为每个标题获得了相同的博客
Posted
技术标签:
【中文标题】大家好,当我单击标题按钮时,我为每个标题获得了相同的博客【英文标题】:Hello guys when i click on the button that is the title i got the same blog for each title 【发布时间】:2021-07-25 07:17:55 【问题描述】:当我在 django 标题上单击 c 时,我得到 django 帖子,当我单击 javascript 标题时,我得到 django 帖子,以太没有使用任何框架工作,这是我的博客页面,我真的尝试了所有我知道的解决方案,但不幸的是什么也没发生 And here an image
blog.html
% for blog in blogs %
<div class="col-xl-12 col-md-6 col-xs-12 blog">
<div class="right-text-content">
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal">
<h2 class="sub-heading">blog.title|title</h2>
</button>
<!-- Modal -->
<div class="modal fade align-self-end mr-3 " id="myModal" tabindex="1" role="dialog"
aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">blog.title|title</h5>
<h6 class="float-right">blog.created_at</h6>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
blog.content|linebreaks
</div>
<div class="modal-footer">
<h5>Created by blog.name</h5>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<p>
<br>
<a rel="nofollow noopener" href="blog.name_url" target="_parent">blog.name</a>
<br>
blog.content|linebreaks
</p>
blog.created_at
</div>
</div>
% endfor %
views.py
from django.shortcuts import render
from .models import DigitalTeam, Blog
def index(request):
pers = DigitalTeam.objects.all()
return render(request, 'index.html', 'pers':pers)
def blog(request):
pers = DigitalTeam.objects.all()
blogs = Blog.objects.all()
return render(request, 'blog.html', 'pers':pers, 'blogs':blogs)
urls.py
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
path('blog', views.blog, name='blog'),
]
那么,伙计们,我错过了什么
【问题讨论】:
【参考方案1】:要在模态中获取单个博客详细信息,您需要将博客 ID 作为道具传递给模态。 可以通过在按钮 data-target 属性中添加 blog.id 并在 modal id 属性中接收 blog.id 来完成。 下面给出的解决方案,
% for blog in blogs %
<div class="col-xl-12 col-md-6 col-xs-12 blog">
<div class="right-text-content">
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModalblog.id">
<h2 class="sub-heading">blog.title|title</h2>
</button>
<!-- Modal -->
<div class="modal fade align-self-end mr-3 " id="myModalblog.id" tabindex="1" role="dialog"
aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">blog.title|title</h5>
<h6 class="float-right">blog.created_at</h6>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
blog.content|linebreaks
</div>
<div class="modal-footer">
<h5>Created by blog.name</h5>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<p>
<br>
<a rel="nofollow noopener" href="blog.name_url" target="_parent">blog.name</a>
<br>
blog.content|linebreaks
</p>
blog.created_at
</div>
</div>
% endfor %
【讨论】:
以上是关于大家好,当我单击标题按钮时,我为每个标题获得了相同的博客的主要内容,如果未能解决你的问题,请参考以下文章
java - 如何在java脚本或jquery中计算相同按钮单击3次和4次时的间隔时间
单击后退按钮时,在 RecyclerView 中获得相同的项目位置
Hadoop Kerberos:hdfs 命令“找不到任何 Kerberos tgt”,即使我使用 kinit 获得了一张票