Django用內(nèi)置方法實(shí)現(xiàn)簡單搜索功能的方法
Model中分別提供了filter方法和icontains方法實(shí)現(xiàn)簡單的搜索功能。
html頁面中實(shí)現(xiàn)搜索框模板api_test_manage.html中增加以下內(nèi)容
<form method=’get’ action=’/api_search/’>{% csrf_token %}<input type=’search’ name=’api_test_name’ placeholder=’流程接口名稱’ required><button type=’submit’>搜索</button></form>

ApiTest/apiviews.py中增加函數(shù)
# 搜索功能@login_requireddef api_search(request): username = request.session.get(’user’, ’’) search_apiTestName = request.GET.get(’api_test_name’, ’’) # 獲取name屬性=api_test_name的值,即搜索框輸入內(nèi)容 apitest_list = ApiTest.objects.filter(apiTestName__icontains=search_apiTestName) return render(request, ’apitest_manage.html’, {’user’: username, ’apitests’: apitest_list})urls文件中增加路徑
AutoTestPlat/urls.py中增加連接映射
urlpatterns = [ path(’admin/’, admin.site.urls), path(’api_search/’, apiviews.api_search),
搜索結(jié)果如下

到此這篇關(guān)于Django用內(nèi)置方法實(shí)現(xiàn)簡單搜索功能的方法的文章就介紹到這了,更多相關(guān)Django 內(nèi)置方法實(shí)現(xiàn)搜索內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. 3分鐘學(xué)會(huì)如何上手supervisor看門狗2. Docker暴露2375端口導(dǎo)致服務(wù)器被攻擊問題及解決方法3. 解決VUE項(xiàng)目使用Element-ui 下拉組件的驗(yàn)證失效問題4. CSS3實(shí)例分享之多重背景的實(shí)現(xiàn)(Multiple backgrounds)5. 解決VUE 在IE下出現(xiàn)ReferenceError: Promise未定義的問題6. ASP實(shí)現(xiàn)加法驗(yàn)證碼7. jsp網(wǎng)頁實(shí)現(xiàn)貪吃蛇小游戲8. 利用FastReport傳遞圖片參數(shù)在報(bào)表上展示簽名信息的實(shí)現(xiàn)方法9. 輕松學(xué)習(xí)XML教程10. 表單中Readonly和Disabled的區(qū)別詳解

網(wǎng)公網(wǎng)安備