【发布时间】:2020-02-21 07:36:41
【问题描述】:
我想在我的网站中添加搜索,我想从我的页面中搜索 (html)
** 注意:我想获取标签标签,例如:
我有一个名为“test”的标签,当用户在搜索栏中写“test”时,我想在新页面中查看用户的标签
- 我的标签是这样的:
<label id="label_main_app">
<img id="img_main_app_first_screen" src="{% static " images/android_studio.jpg " %}" alt=""> test
<br>
<br>
<p id="p_size_first_page">this is an test app
<br>
<br>
<a href="https://www.fb.com" type="button" class="btn btn-primary"><big> See More & Download </big></a>
</p>
</label>
- 我总是在结果页面中收到此消息:未找到
我的代码:* html 主页中的这个表单
<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>
这是我的 view.py 代码:
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})`
最后这是我在 html 结果页面中的代码:
<div class="container">
{% if search %}
{{ search }}
{% else %}
<h2>not found</h2>
{% endif %}
</div>
有什么帮助吗?
【问题讨论】:
-
我不明白的是在
views.py中,您首先分配input='search',然后分配my_template_keyword = ['label']。在您的if语句中,测试input == my_template_keyword是否绝对不相等? -
是的,它不相等,我必须做什么?
标签: python django python-3.x django-templates