这是我的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
页面中使用这个变量值。
请告诉我如何解决这个问题,我已经被困在这里两个星期了
您应该在链接href中添加标题
这将输出类似于
<a href="http://localhost:8000/content?heading=foobar"></a>
的内容,然后当用户单击此链接时,heading
参数将添加到request.GET
中您需要相应地修改视图
heading = request.GET['heading']
相关问题 更多 >
编程相关推荐