The quest: add simple search on top of a django-table to filter it's values.
Problem: f^tup somewhere and getting this error when passing request after putting value in search window:
Method Not Allowed (POST): /warscrolls/
[22/Jun/2018 10:27:17] "POST /warscrolls/ HTTP/1.1" 405 0
My url is like this:
url(r'^warscrolls/$', ScrollListView.as_view(filter_class=ScrollListFilter,
template_name='scroll_list.html'), name='warscrolls'),
My search form in html template looks like this:
<form method="post" class="form-inline form-search pull-right">
{% csrf_token %}
<div>
<input id="search_form_id" name="search" type="text" class="form-control col-md-3" placeholder="ID, Name, Account #, ZIP"{% if search %} value="{{ search }}"{% endif %}>
<button type="submit" class="btn btn-small btn-dark"><i class="fa fa-search"></i> Search</button>
</div>
</form>
What am I missing?
To enable POST
request your class based view should implement post()
method. But django ListView
class does not implemented post()
method by default and this raise the error.
Actually it's common practice to use GET
request for search option, so to fix error you can simple update your html form like this:
<form method="get" class="form-inline form-search pull-right">
<div>
<input id="search_form_id" name="search" type="text" class="form-control col-md-3" placeholder="ID, Name, Account #, ZIP"{% if search %} value="{{ search }}"{% endif %}>
<button type="submit" class="btn btn-small btn-dark"><i class="fa fa-search"></i> Search</button>
</div>
</form>