Я пытаюсь реализовать панель поиска в django, если элемент поиска, присутствующий в базе данных, отображается на веб-странице. Но запрос показа возвращает значение None. Я новичок в Джанго. Пожалуйста, помогите мне в этом
views.py
def search(request):
if request.method == 'GET':
form = LocForm(request.POST)
if form.is_valid():
search_query = request.GET.get('search_box', None)
print(search_query)
FirstLoc_list_obj = FirstLoc_List.objects.filter(address__icontains=search_query)
SecondLoc_list_obj= SecondLoc_list.objects.filter(address__icontains=search_query)
if (len(FirstLoc_list_obj) or len(SecondLoc_list_obj)) > 0:
print("Locaton Found")
return render(request, 'location_test.html', {'FirstLoc_list_obj': FirstLoc_list_obj, 'SecondLoc_list_obj': SecondLoc_list_obj})
else:
print("Location Not Found")
return render(request, 'location_test.html', {})
return render(request, 'location_test.html', {})
return render(request, 'location_test.html', {})
urls.py
urlpatterns = [
path('search/', views.search, name="search"),
]
location_test.html
<form type="get" action="#" style="margin: 0">
{% csrf_token %}
<label>Locations:-</label>
<input id="search_box" type="text" name="search_box" placeholder="Search..." >
<button id="search_submit" type="submit" >Submit</button>
</form>