0
私は脆弱な検索バーを作成したいが、すべてを行ったが残念なことに、submitを押すと検索機能に結果が表示されない。 しかし、端末は成功を示し、 "POST /注入/ HTTP/1.1" 200 596脆弱なDjango検索バーを作成する
views.py
@csrf_exempt
def search_form(request):
if 'searchField' in request.POST:
query= "SELECT * FROM injection_search WHERE injection_search.name LIKE '%searchField%'"
print(query)
item = search.objects.raw(query)
else:
item = search.objects.all()
return render(request, 'home.html', {'item' : item})
template/home.html
{% load static %}
<link href="{% static 'css/style.css' %}" rel="stylesheet"></link>
<h1 class="page-header">INJECTION</h1>
<form action="" method="POST">
<input type="text" name="searchField" id="searchField" placeholder="search trainers..">
<button type="submit">Find</button>
</form>
<h1> Search Page </h1>
<h3> Injection demo</h3>
<div class="shopping-container">
<table border="3" cellspacing="0" cellpadding="10">
<tbody>
<tr>
<th>Title</th>
<th>Description</th>
<th>Quantity</th>
</tr>
<!--{% for search in item %}-->
<tr>
<td>{{ search.name}}</td>
<td>{{ search.description }}</td>
<td>{{ search.price}}</td>
</tr>
<!--{%endfor%}-->
</tbody>
</table>
</div>
model.py
app_name = 'injection'
urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^injection/$', views.search_form, name='search_form'),
]
あなたが今までSQLに掲示値を渡しません。 –
申し訳ありません、あなたは私のために少し説明できますか?事前に感謝します –
私のsearchFieldは私の検索フィールドを表しているので、私はここに投稿していると思いますが、間違っているかもしれません。 –