I want to do a random search in the database, but it is not working. I want to take a sentence, and show it on the screen, it will be changed every time I refresh the screen.
My view.py:
def busca_tendencia(request):
tendencias = Frase.objects.all().order_by('?')
return render(request, 'busca/index.html', {'tendencias': tendencias})
No html:
{{ tendencias.frase }}
My models.py
class Frase(models.Model):
titulo = models.CharField(max_length=300, blank=False)
frase = models.TextField()
data = models.DateTimeField(default=timezone.now)
class Meta:
verbose_name = 'Frase'
verbose_name_plural = 'Frases'
When accessing the page does not return anything, nor error. And the phrase does not appear.