在博客文章中搜索关键字后,如何从搜索页面检索博客文章?

时间:2020-12-19 13:42:40

标签: python-3.x django django-views django-forms django-templates

我在搜索页面上遇到问题,在数据库中成功搜索关键字后,它给了我结果,但是当我在该搜索页面上单击该结果时,它没有将我定向到原始帖子,让我显示如果有人可以帮助我,我的意思是什么;

I need this >>> /blog/blogpost/my_article

Instead i am redirected to this >>>/blog/search/blogpost/my_article

在视图中使用 Django/Python,我的搜索功能:

def search(request):
    query = request.GET['search']
    myposts = Blogpost.objects.filter(title__icontains=query)
    context = {'myposts': myposts}
    return render(request, 'blog/search.html', context)

网址:

path("search/", views.search, name="search")

{ # 是一个项目里面的APP}

如果你明白我在说什么,请告诉我,谢谢

0 个答案:

没有答案