在Django URL中添加?q = search + term [英] Add ?q=search+term in django url

查看:34
本文介绍了在Django URL中添加?q = search + term的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将弹性搜索与django集成在一起,但首先我需要在url中获得一个不错的参数

I want to integrate elastic search with django but first I need to get a nice parameter in url

http://127.0.0.1:8000/search?q=search+term

(视图的)urls.py

urls.py (of the view)

urlpatterns = [
    path('?q=', SearchIndexView.as_view(), name="search-index"),
]

(应用程序的)urls.py

urls.py (of the app)

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('home.urls')),
    path('u/', include('user.urls')),
    path('search', include('search.urls')),
]

到目前为止,这是我所拥有的,但是我无法弄清楚如何使其工作.我想尽可能使用tha path()而不是url()

That is what I have so far but I cant figure out how to make it work. I want to use tha path() and not url() if possible

推荐答案

您无需定义 urls.py 中的url查询字符串.您可以像这样保留网址:

You don't need to define url query strings in urls.py. You can keep the url like this:

path('', SearchIndexView.as_view(), name="search-index"),

,在 SearchIndexView 中,您可以这样操作:

and in SearchIndexView you can do it like this:

q = request.GET.get('q')

这篇关于在Django URL中添加?q = search + term的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆