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)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. ASP動(dòng)態(tài)網(wǎng)頁制作技術(shù)經(jīng)驗(yàn)分享2. jsp實(shí)現(xiàn)登錄驗(yàn)證的過濾器3. Xml簡介_動(dòng)力節(jié)點(diǎn)Java學(xué)院整理4. jsp文件下載功能實(shí)現(xiàn)代碼5. 如何在jsp界面中插入圖片6. JSP之表單提交get和post的區(qū)別詳解及實(shí)例7. 詳解瀏覽器的緩存機(jī)制8. vue3+ts+elementPLus實(shí)現(xiàn)v-preview指令9. .Net加密神器Eazfuscator.NET?2023.2?最新版使用教程10. phpstudy apache開啟ssi使用詳解
