我正在尝试通过发布的评论制作搜索引擎。目标是尽可能最简单地搜索评论。请参阅下面的程序架构:
views.py
class Comentario (models.Model):
titulo = models.CharField(max_length=50)
texto = models.CharField(max_length=200)
autor = models.ForeignKey (Perfil, null=True, blank=True, on_delete=models.CASCADE)
fecha_publicacion = models.DateTimeField(auto_now_add=True)
tag = models.ManyToManyField(Tags, blank=True)
def __str__(self):
return (self.titulo)
urls.py
<form id="searchform" action="search/" method="GET" accept-charset="utf-8">
<button class="searchbutton" type="submit">
<i class="fa fa-search"></i>
</button>
<input class="searchfield" id="searchbox" name="q" type="text" placeholder="Search" id="busqueda">
</form>
{% endblock %}
models.py
{% extends 'base/base.html' %}
{% block content %}
<table class="table table-striped">
<thead class="thead-default">
<tr>
<td>Titulo</td>
<td>Descripcion</td>
<td>Autor</td>
<td>Fecha de publicación</td>
<td>Etiqueta</td>
</thead>
<tbody>
{% if qs %}
{% for comentario in object_list %}
<tr>
<td>{{comentario.titulo}}</td>
<td>{{comentario.texto}}</td>
<td>{{comentario.autor}}</td>
<td>{{comentario.fecha_publicacion}}</td>
{% for tag in comentario.tag.all %}
<td>{{ tag.nombre }}</td>
{% endfor %}
{% endfor %}
</tr>
{% else %}
<h1>No hay registros de comentarios</h1>
{% endif %}
</tbody>
</table>
cometario_listar.html (我在其中创建了搜索按钮)
import re
s = 'Me_of_temp_max: 13.91 Me_of_temp_min: 11.33 Me_of_p_max: 14.25 Me_of_p_min: 14.53'
regex = re.compile('(\w+):\s(\d+\.\d+)')
{k: float(v) for k, v in regex.findall(s)}
search.html
{'Me_of_p_max': 14.25,
'Me_of_p_min': 14.53,
'Me_of_temp_max': 13.91,
'Me_of_temp_min': 11.33}
问题在于它不起作用。 “http://127.0.0.1:8000/home/search/?q=nueva”正确显示,但不会进行任何过滤。是否可以使用相同的.html文件(comentario_listar.html)进行搜索?
提前感谢您的帮助。