简体   繁体   English

如何在新页面中显示 django 搜索结果

[英]how to display django search result in new page

i want to display my django search result on a new html page instead of the page where the search bar is.我想在新的 html 页面而不是搜索栏所在的页面上显示我的 django 搜索结果。 i have tried manipulating my form tag and it still does'nt redirect to the page when i search, rather it stays on the same page.我已经尝试操作我的表单标签,但当我搜索时它仍然不会重定向到页面,而是停留在同一页面上。

index.html索引.html

<form action="{% url 'elements:all-elements' %}" method="get">
  <input type="text" class="form-control" name="q" value="{{ request.GET.q }}" type="text" placeholder="Search Free Web Elements and Resources">
  <button type="submit" class="btn bt-round" ><b><i class="bi bi-search"></i></b></button>
</form>

views.py - this is the view handling the seach, i dont know if anything would be appended there views.py - 这是处理搜索的视图,我不知道是否会在此处附加任何内容

# Search Function
    query = request.GET.get("q")
    if query:
        vectors = vectors.filter(
            Q(title__icontains=query)).distinct()

You can render new template for your search results.您可以为搜索结果呈现新模板。


def search(request):
    query = request.GET.get("q")
    vectors = Model.objects.all()
    if query:
       vectors = vectors.filter(
            Q(title__icontains=query)).distinct()
    context = {"vectors":vectors}
    return render(request,  "template",  context)

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

相关问题 如何在SAME页面上显示搜索结果(django + haystack + elasticsearch)? - How to display search results(django+haystack+elasticsearch) on the SAME page? Django:当我单击产品页面中的产品时,如何在新页面中显示产品的详细信息 - Django: How to display details of a product in a new page when i click on a product in the product page 如何在前端显示搜索结果分数百分比? - How to display the search result score as percentage in the frontend? 如何在 html django 页面中显示我的 sqlite 查询的结果 - How can I display the result of my sqlite query in a html django page 如何使用 Django 将搜索查询结果保存到模型中? - How to save search query result into the model with Django? 如何使用 django 将 Paginator 添加到搜索结果? - how to add Paginator to search result using django? 如何从搜索栏中获取用户输入以显示在页面中? Django - How do I get user input from search bar to display in a page? Django CS50 项目 1 帮助 - Wiki Search w/ Django - 卡在如何保存新页面 - CS50 Project 1 Help - Wiki Search w/ Django - Stuck on how to save a new page 如何阅读保存的谷歌搜索结果页面? - How to read saved google search result page? 如何在 django 项目中使用 ajax 显示搜索结果? - How to display search results with ajax in django project?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM