django中的反向错误没有显示它无法逆转

时间:2017-07-14 12:44:25

标签: django

我不认为我正在倒车''但我仍然收到一个错误:反向''未找到。 ''不是有效的视图函数或模式名称。不知道错误来源的位置,因为它没有显示没有找到反向的错误。 enter image description here

urls.py

    url(r'^search_page/$', views.index, name='search_page'),
url(r'^search_customer/$',views.ajax_customer_search,name='search_customer'),

模板:base.html文件



<!DOCTYPE html>
<html>

<head>
<title>Django/jQuery AJAX Search</title>
         <script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.2.6.js"></script>

{% block extra_js %}

{% endblock %}
    </head>

<body>
<div id="centered">

{% block main %}{% endblock %}

</div>
</body>
</html>
&#13;
&#13;
&#13;

模板:index.html的

&#13;
&#13;
{% extends "base.html" %}

{% block extra_js %}

<script type="text/javascript">
$( document ).ready( function() {
$( "#searchSubmit" ).click( function() {
q = $( "#q" ).val();
$( "#results" ).html( "&nbsp;" ).load( "{% url search_customer %}?q=" + q );
});
});

$( document ).ajaxStart( function() {
$("#spinner").show();
}).ajaxStop( function() {
$( "#spinner" ).hide();
});
</script>

{% endblock %}

{% block main %}

<div>
<input id="q" type="text"/>
<input id="searchSubmit" type="submit" value="Search"/>
<br/>
<span class="hint">Type in a query string to search for users</span>
<div class="margin">
<span id="spinner"><img src="http://upload.wikimedia.org/wikipedia/commons/d/de/Ajax-loader.gif"/></span>
<div id="results"></div>
</div>
</div>
{% endblock %}
&#13;
&#13;
&#13;

&#13;
&#13;
{% if results|length %}

<table>
<tr class="even">
<td colspan="3" class="right">
<strong>Found {{ results|length }} users</strong>
</td>
</tr>

{% for user in results %}
    <tr class="{% cycle "odd" "even" %}“>
<td><strong>{{ forloop.counter }}.</strong></td>
<td>
{{ user.fName }} {{ user.lName}}<br>
<span class="hint">{{ user.id}}</span>
</td>
<td class="right">
done
</td>
</tr>
{% endfor %}
    </table>
{% else %}
    <div class="note">
Your search yielded no results
</div>
{% endif %}
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:3)

在index.py文件中

尝试

$( "#results" ).html( "&nbsp;" ).load( "{% url 'search_customer' %}?q=" + q );