Я хочу реализовать поиск с django и ajax.
HTML:
<form class="form-horizontal action-form filter-form" method="get" id="search-form-panel">
{% csrf_token %}
<div class="form-group">
<div class="col-lg-6">
<input type="text" name="product-title" class="form-control" placeholder="products" id="search-text-panel">
</div>
<div class="col-lg-6">
<button type="button" class="btn btn-success search-btn">search</button>
</div>
</div>
</form>
<div class="table-responsive" id="manager-list-container">
<table class="table table-striped table-bordered table-hover" id="basic_list" style="width:100%">
<thead>
...
<script>
let updateProductSearchUrl = '{% url "update-product-search-item" %}';
</script>
<script type="text/javascript" src="/static/product/panel-update-product.js?v={{ SITE_VERSION }}"></script>
и в JS:
$(document).ready(function () {
console.log('it is calling JS part');
$('.search-btn').click(function () {
submitSearch();
});
$("#search-text-panel").keyup(function (e) {
if (e && e.keyCode === 13) {
submitSearch();
} else if (e) {
let searchText = $('#search-text-panel').val().trim();
if (searchText.length > 3)
submitSearch();
}
e.stopPropagation();
e.preventDefault();
return false;
});
function submitSearch() {
let searchText = $('#search-text-panel').val().trim();
console.log(updateProductSearchUrl);
$.get({
url: updateProductSearchUrl,
data: {'q': searchText},
method: 'GET',
success: function (res) {
if (res) {
$('#basic_list').find('tbody').empty().append(res.res);
}
}
});
}
});
ursls.py:
path('update-product-search-item/', views.update_product_search_item, name='update-product-search-item'),
path('panel', views.product_panel_view, name='product-panel'),
path('panel/product-type/add', views.product_panel_view_add, name='panel-product-type-add'),
path('panel/product-type/update', views.product_panel_view_update, name='panel-product-type-update'),
path('panel/not-exist', views.product_panel_not_exist, name='panel-product-not-exist'),
path('panel/not-exist/details/<int:product_id>', views.product_panel_not_exist_details, name='panel-product-not-exist-detail'),
path('panel/cargo', views.product_panel_cargo, name='panel-product-cargo'),
path('panel/cargo/create', views.product_panel_create_cargo, name='panel-product-cargo-create'),
и в представлениях .py:
@staff_only(url_name='panel/product-type/update')
def update_product_search_item(request):
print('@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@2')
print('it is calling this funciton')
try:
products = ProductType.objects.first()
res = render_to_string('product/panel_update_product_type.html',
{'products': products}, request=request)
return HttpResponse(json.dumps({'res': res}), content_type="application/json")
except Staff.DoesNotExist:
return HttpResponseForbidden()
с помощью этих кодов, когда я нажимаю на поле поиска, он возвращает:
jquery -3.1.1.min. js: 4 GET http://127.0.0.1: 8082 / admin / login /? Next = / admin / update-product-search-item /% 3Fq% 3Dproducts net :: ERR_TOO_MANY_REDIRECTS
что это за ошибка и как ее исправить?