问题
I want to add search in my website and I want search from my pages (html)
** note : i want take the label tag , I mean
I have label tag called test and when user write in search bar test I want to show the label to user.
always I got this message in result page : not found
So, I created this form in home html page
<form class="" action="{% url 'test_search_page'%}" method="get">
<div class="md-form mt-0 search-bar" id="search_form">
<input id="search_box" autocomplete="off" onkeyup="searchFunction()" class="form-control" type="text" placeholder="Write Here to Search ..." aria-label="Search" name="search">
</div>
</form>
- this is my ' label ' in html that what i want to grab it and show it for user when search about ex : (test or android studio or gta v for example )
<label id="label_main_app"> <img id="img_main_app_first_screen" src="{% static "images/android_studio.jpg" %}" alt="" > Android Studio 2019 Free Download <br><br> <p id="p_size_first_page">Android Studio 2019 Free Download Latest Version for Windows. It is full offline installer standalone setup of Android Studio 2019 <br> <br> <a href="https://www.fb.com" type="button" class="btn btn-primary"><big> See More & Download </big> </a> </p>
</label>
and this is my view.py code :
def search(request):
input= 'search'
my_template_keyword = ['label']
if 'search' in request.GET and request.GET['search'] and input == my_template_keyword:
return render(request, 'home_page/testforsearch.html', {'search:':search})`
finally this is my code in html result page :
<div class="container">
{% if search%}
{{search}}
{%else%}
<h2>not found</h2>
{%endif%}
</div>
来源:https://stackoverflow.com/questions/58508935/search-input-on-every-pages-django