Answer the question
In order to leave comments, you need to log in
How to select a random record from a database in Django and output the result to a template?
There is models.py :
class Questions(models.Model):
question = models.CharField('Вопрос',max_length=200)
q_category = models.CharField('Тема',max_length=200)
class Meta:
verbose_name = "Вопрос"
verbose_name_plural = "Вопросы"
def __str__(self):
return self.question
from django.shortcuts import render
from django.http import HttpResponse
def index(request):
return render(request, 'cards/index.html', {})
{% extends 'base.html' %}
{% block content %}
<div>
<h1>Генератор рандомных вопросов</h1>
<p>Тема вопроса:</p> # выбрать q_category из models.py
<button>Получить вопрос</button>
</div>
{% endblock %}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question