[英]I want to Pass the text inside anchor tag when clicked on that tag and to show the same text on the directed page
这是我的discover.html
文件
<form action="POST">
<div class="swipe-area">
<div class="swiper-container mySwiper">
<div class="swiper-wrapper">
{% for topic in topics %}
<div class="swiper-slide">
<a href="{% url 'content' %}" style="color: white; text-decoration: none;">
<h1 name="headings" data-tooltip="{{ topic.description }}" data-tooltip-location="bottom">
{{ topic.heading }}
</h1>
</a>
</div>
{% endfor %}
</div>
<div class="swiper-button-next"></div>
<div class="swiper-button-prev"></div>
</div>
<!-- <div class="swiper-button-next"></div>
<div class="swiper-button-prev"></div> -->
</div>
</form>
当单击该链接到该链接带我的页面时,我想将 h1 标记的值传递给{{ topic.heading }}
。
<a href="{% url 'content' %}" style="color: white; text-decoration: none;">
<h1 name="headings" data-tooltip="{{ topic.description }}" data-tooltip-location="bottom">
{{ topic.heading }}
</h1>
</a>
下面是我的views.py
文件
def content(request):
heading = request.GET['headings']
content = Search.objects.all().filter(title__contains = heading)
context = {'content': content}
return render(request, 'search/content.html', context)
所以我希望在我的content.html
页面中使用该变量值。 请告诉我如何解决这个问题,我已经被困在这里 2 周了。
您应该在链接 href 中添加标题。
<a href="{% url 'content' %}?heading={{topic.heading}}" style="color: white; text-decoration: none;">
<h1 name="headings" data-tooltip="{{ topic.description }}" data-tooltip-location="bottom">
{{ topic.heading }}
</h1>
</a>
这将输出类似<a href="http://localhost:8000/content?heading=foobar"></a>
,然后当用户单击此链接时, heading
参数将添加到request.GET
。
您需要相应地修改您的视图heading = request.GET['heading']
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.