django autocomplete_light对象没有属性'get_absolute_url'错误

时间:2015-01-04 03:50:36

标签: django url autocomplete

我正在尝试实现一个具有自动完成功能的搜索框,并且正在使用autocomplete_light库。我有一个班级

class GenAutocomplete2(autocomplete_light.AutocompleteGeneric):
   choices = (
      Person.objects.all(),
      Other.objects.all()
   )
   search_fields = (
      ('first_name', 'last_name'),
      ('name',)
   )

应该允许我通过first_name或last_name搜索Person对象,并按名称搜索其他对象。我注册了这样的自动完成:

  autocomplete_light.register(GenAutocomplete2)

并将其显示在模板文件中,如下所示:

<html>
<head>
   <title>Testing</title>
   <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.js" type="text/javascript"></script>
   {% include 'autocomplete_light/static.html' %}
</head>
<body>
   <h1> Search Page </h1>

   <form action="" method="post">

      {% csrf_token %}
      {{ form }}
      <input type="submit" value="Submit">
   </form>
</body>
</html>

使用视图

   form = MyForm()
   return render(request, 'test_html.html', {'form': form})

但是,我收到错误&#39; GenAutocomplete2&#39;对象没有属性&#39; get_absolute_url&#39; 当我转到http://localhost:8000/autocomplete/时,我会看到以下内容:error

GenAutocomplete2没有自动填充网址

0 个答案:

没有答案