我想将 autocomplete-light 集成到 django cms 中的模板中
我在应用程序“医生”中的看法:
def search(request):
q = request.GET.get('q', '')
queries = {}
queries['person'] = Person.objects.filter(name__icontains=q)[:6]
return render(request, 'search.html', queries)
urls.py (CMS)
urlpatterns = i18n_patterns('',
url(r'^autocomplete/', include('autocomplete_light.urls')),
url(r'^admin/', include(admin.site.urls)), # NOQA
url(r'^sitemap\.xml$', 'django.contrib.sitemaps.views.sitemap',
{'sitemaps': {'cmspages': CMSSitemap}}),
url(r'^select2/', include('django_select2.urls')),
#url(r'^doctor/', include('doctor.urls')),
url(r'^', include('cms.urls')),
)
urls.py(应用医生)
urlpatterns = [
url(r'^', views.search, name='search'),
]
搜索.html
<input type="text" name="q" id="navigation_autocomplete" style="width: 270px;font-size: 16px;" />
<style type="text/css">
/* cancel out django default for now, or choices are white on white */
#header a.choice:link, #header a.choice:visited {
color: black;
}
</style>
<span class="separator">Person</span>
{% for p in person %}
<a class="block choice" href="{{ p.url }}">{{ p.name }}</a>
{% endfor %}
<script type="text/javascript">
$(document).ready(function() {
$('#navigation_autocomplete').yourlabsAutocomplete({
url: '{% url 'NoIdeaWhatToEnterHere' %}',
choiceSelector: 'a',
}).input.bind('selectChoice', function(e, choice, autocomplete) {
document.location.href = choice.attr('href');
});
});
</script>
search.html 是一个进入 CMS 页面的 apphook,其 URL 为“/en/list/”或 /ru/list/”,具体取决于语言。
我必须在 javascript 部分设置什么 url?目前我总是收到 NoReverseMatch 错误。
编辑:
根据要求提供错误详细信息:
NoReverseMatch at /en/search/
Reverse for 'search' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
Request Method: GET
Request URL: http://primo2-caliph007-8.c9users.io:80/en/search/
Django Version: 1.7.10
Exception Type: NoReverseMatch
Exception Value:
Reverse for 'search' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
Exception Location: /home/ubuntu/workspace/virt7/local/lib/python2.7/site-packages/django/core/urlresolvers.py in _reverse_with_prefix, line 468
Python Executable: /home/ubuntu/workspace/virt7/bin/python