按照tango_with django教程,第15.2章,添加内联建议,但是当我在搜索框中输入代码时,代码无法按预期运行,即使我输入的名称是有效类别,它也不会返回任何类别 这是代码
views.py
<ul class = "nav nav-list">
<div class = "du">
{% if cat_list %}
{% for cat in cat_list %}
<li><a href = "/rango/category/{{cat.url}}">{{cat.name}}</a></li>
{% endfor %}
{% else %}
<li>No categories at present.<li>
{% endif %}
</div>
category_list.html
<div class = "well sidebar-nav">
<ul class = "nav nav-list">
<li class = "nav-header">Find a Category !</li>
<form>
<label></label>
<li><input class = "search-query" type = "text" name="suggestion" value ="" id = "suggestion"/><li>
</form>
</ul>
{% if cat_list %}
<div id = "cats">
{% include 'category_list.html' %}
</div>
{% endif %}
</div>
表格
url(r'^suggest_category/$',suggest_category),
urls.py
$(document).ready(function(){
$('#likes').click(function(){
var catid;
catid = $(this).attr("data-catid");
$.get('/rango/like_category/', {category_id:catid},function(data){
$('#like_count').html(data);
$('#likes').hide();
});
});
$('#suggestion').keyup(function(){
var query;
query = $(this).val();
$.get('/rango/suggest_category/',{suggestion:query}, function(data){
$('#cats').html(data);
});
});
});
rangoajax.js
[ $(git rev-parse --show-toplevel) == $(pwd) ]