简体   繁体   English

我想在单击该标签时传递锚标签内的文本并在定向页面上显示相同的文本

[英]I want to Pass the text inside anchor tag when clicked on that tag and to show the same text on the directed page

This is my discover.html file这是我的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>

I want to pass the value of h1 tag that is {{ topic.heading }} when clicked on that link to the page that link takes me.当单击该链接到该链接带我的页面时,我想将 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>

Below is my views.py file下面是我的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)

So I want that variable value in my content.html page.所以我希望在我的content.html页面中使用该变量值。 Please tell me how to tackle this problem, I have been stuck here for 2 weeks.请告诉我如何解决这个问题,我已经被困在这里 2 周了。

You should add the heading in the link href.您应该在链接 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>

This will output something like <a href="http://localhost:8000/content?heading=foobar"></a> , then when user clicks on this link, the heading parameter will be added in request.GET .这将输出类似<a href="http://localhost:8000/content?heading=foobar"></a> ,然后当用户单击此链接时, heading参数将添加到request.GET

You need to modify your view accordingly heading = request.GET['heading'] .您需要相应地修改您的视图heading = request.GET['heading']

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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