django CMS:在模板中集成自动完成功能

时间:2015-11-22 19:36:22

标签: javascript django django-cms django-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(app doctor)

urlpatterns = [

    url(r'^', views.search, name='search'),

] 

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是一个apphook进入CMS页面,其中包含“/ en / list /”或/ ru / list /“,具体取决于语言。

我必须在javascript部分设置什么网址? 目前我总是得到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

0 个答案:

没有答案