Codes on views.py

def searching(request):
    prod = None
    query = None
    if 'q' in request.GET:
        query = request.GET.get('q')
        prod = Products.objects.all().filter(Q(name__contains=query) | Q(des__contains=query))

    return render(request, 'search.html', {'qr': query, 'pr': prod})

Codes on urls.py

urlpatterns = [
    path('', views.home, name='hm'),
    path('<slug:c_slug>/', views.home, name='prod_cat'),
    path('<slug:c_slug>/<slug:product_slug>', views.prodetails, name='details'),
    path('search', views.searching, name='searching'),
]

Codes on search.html


 <div class="row flex px-xl-5">
{% for i in pr %}

            <div class="col-lg-3 col-md-4 col-sm-6">
                <div class="product-item bg-light mb-4">
                    <div class="product-img position-relative overflow-hidden">
                        <a href="{{i.get_urls}}"><img class="img-fluid w-100" src="{{i.img.url}}" alt="" style="height:250px; width:500px;">
                        </a>
                    </div>

                    <div class="text-center py-4">
                        <a class="h6 text-decoration-none text-truncate" href="{{i.get_url}}">{{i.name}}</a>
                        <p>{{i.des|truncatechars:80}}</p>
                        <div class="d-flex align-items-center justify-content-center mt-2">
                            <h5>RS {{i.price}}</h5><h6 class="text-muted ml-2"><del>RS 123.00</del></h6>
                        </div>
                        <p>Stocks left: {{i.stock}}</p>
                        <div class="d-flex align-items-center justify-content-center mb-1">
                            <small class="fa fa-star text-primary mr-1"></small>
                            <small class="fa fa-star text-primary mr-1"></small>
                            <small class="fa fa-star text-primary mr-1"></small>
                            <small class="fa fa-star text-primary mr-1"></small>
                            <small class="fa fa-star text-primary mr-1"></small>
                            <small>(99)</small>
                        </div>
                    </div>
                </div>
            </div>



{% endfor %}
     </div>

Codes on base.html

<div class="col-lg-4 col-6 text-left">
                <form action="{% url 'searching' %}" method="get">
                    <div class="input-group">
                        <input type="text" class="form-control" placeholder="Search for products">
                        <div class="input-group-append">
                            <span class="input-group-text bg-transparent text-primary">
                                <i class="fa fa-search"></i>
                            </span>
                        </div>
                    </div>
                </form>
            </div>

Actually, my problem is that when I search for a product, on the URL tab, it should be shown like this: "http://127.0.0.1:8000/search?q=name" and when I search, my URL tab shows only like this: "http://127.0.0.1:8000/search?" Please help me to fix this issue.

我需要解决此问题,请帮助我解决此问题.

推荐答案

向您的HTML输入元素添加一个name属性,如下所示

<input type="text" class="form-control" placeholder="Search for products" name="q">

Python相关问答推荐

使用plotnine和Python构建地块

将特定列信息移动到当前行下的新行

ModuleNotFound错误:没有名为Crypto Windows 11、Python 3.11.6的模块

2D空间中的反旋算法

如何使用pytest来查看Python中是否存在class attribution属性?

如何在Polars中从列表中的所有 struct 中 Select 字段?

Odoo 16使用NTFS使字段只读

pandas在第1列的id,第2列的标题,第3列的值,第3列的值?

提取相关行的最快方法—pandas

Python中的变量每次增加超过1

为什么常规操作不以其就地对应操作为基础?

在方法中设置属性值时,如何处理语句不可达[Unreacable]";的问题?

Gunicorn无法启动Flask应用,因为无法将应用解析为属性名或函数调用.'"'' "

没有内置pip模块的Python3.11--S在做什么?

每次查询的流通股数量

在任何要保留的字段中添加引号的文件,就像在Pandas 中一样

使用xlsxWriter在EXCEL中为数据帧的各行上色

是否需要依赖反转来确保呼叫方和被呼叫方之间的分离?

将时间序列附加到数据帧

Pandas 数据框自定义排序功能