[英]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.