2015-09-10 165 views
4

我正在Django開發一個項目,我想在我的搜索autocomplemente,但我失去了代碼Django-autocomplete-light’s 它不起作用。自動完成與Django的自動完成燈的

首先,我安裝了它:

pip install django-autocomplete-light 

我把經過INSTALLED_APPS和網址:

INSTALLED_APPS = (
    #... 
    'django.contrib.staticfiles', 
    'autocomplete_light' 
) 

# URLS 
url(r'^autocomplete/', include('autocomplete_light.urls')), 

但是我在這裏失去了我。

這是我的模型:

class Tecnico(models.Model): 
    codigo = models.AutoField(primary_key=True) 
    nome = models.CharField(max_length=60) 
    endereco = models.CharField(max_length=60, blank=True, null=True) 
    numero = models.CharField(max_length=10, blank=True, null=True) 
    bairro = models.CharField(max_length=40, blank=True, null=True) 
    cidade = models.IntegerField(blank=True, null=True) 
    fone = models.CharField(max_length=14, blank=True, null=True) 
    cpf = models.CharField(max_length=18, blank=True, null=True) 
    sexo = models.CharField(max_length=1, blank=True, null=True) 
    data_nasc = models.DateField(blank=True, null=True) 
    data_inc = models.DateField(auto_now_add=True, blank=True, null=True) 
    status = models.CharField(max_length=1, blank=True, null=True) 

    class Meta: 
     db_table = 'tecnico' 

,這是我的HTML代碼:

<div class="container"> 
    <form action=""> 
     <div class="col"> 
      <div class="col-1-2 first"> 
       <label class="label" for="nome">Nome</label> 
       <input class="input varchar autocomplete" type="text" autofocus> 
       <ul class="list-autocomplete"> 
        {# Show my list here #} 
       </ul> 
      </div> 
      <div class="col-1-2"> 
       <input class="button no-label" id="action-button" type="button" value="Pesquisar"> 
      </div> 
     </div> 
    </form> 
</div> 
<div class="col"> 
    <table class="container--fluid table"> 
     <thead> 
      <tr> 
       <th>Código</th> 
       <th>Nome</th> 
       <th>Telefone</th> 
       <th>CPF</th> 
       <th>Data de nasc.</th> 
      </tr> 
     </thead> 
     {% for Tecnico in tecnicos %} 
     <tbody> 
      <tr> 
       <td class="align-center">{{Tecnico.codigo}}</td> 
       <td>{{Tecnico.nome}}</td> 
       <td class="align-center">{{Tecnico.fone}}</td> 
       <td class="align-center">{{Tecnico.cpf}}</td> 
       <td class="align-center">{{Tecnico.data_nasc}}</td> 
      </tr> 
     </tbody> 
     {% empty %} 
      <div> 
       Nenhum resultado foi encontrado 
      </div> 
     {% endfor %} 
    </table> 
</div> 
<div class="col"> 
    <div class="float-right align-right no-margin-bottom"> 
     <a class="input button gradient-green" href="/tecnicos-incluir/">Incluir novo</a> 
    </div> 
</div> 

我想在我的HTML顯示列表。

對不起,對於擴展代碼。

我在哪裏將自動完成燈用於工作?

回答