I have this json data {'latest_question_list': ((1, "What's up?", datetime.datetime(2019, 4, 19, 7, 38, 6, 449735)),)} , i want to show this data in my html file can anyone please help me how to show this data in it, here is my whole code added, can anyone please help me to resolve this issue, also i need help why i am getting database result in tuple ?
models.py
import datetime
from django.utils import timezone
from django.db import connection
from django.db import models
class Question():
@classmethod
def get_poll_question(cls):
with connection.cursor() as cursor:
db_table = "polls_question"
cursor.execute('SELECT * FROM '+db_table)
allquestion = cursor.fetchall()
return allquestion
class Choice():
def get_options(cls):
with connection.cursor() as cursor:
db_table = "polls_choice"
cursor.execute("SELECT * FROM "+ db_table+" WHERE question_id = '1' ")
choice_text = cursor.fetchall();
return choice_text
views.py
from django.shortcuts import render
# Create your views here.
from django.http import HttpResponse, HttpResponseRedirect
from django.template import loader
from .models import Choice, Question
from django.urls import reverse
from django.shortcuts import get_object_or_404, render
def index(request):
latest_question_list = Question.get_poll_question()
context = {'latest_question_list': latest_question_list}
print(context)
return render(request, 'polls/index.html', context)
index.html
{% load static %}
<link rel="stylesheet" type="text/css" href="{% static 'polls/style.css' %}">
{% if latest_question_list %}
<ul>
{% for question in latest_question_list %}
<li><a href="">{{ question.question_text }}</a></li>
{% endfor %}
</ul>
{% else %}
<p>No polls are available.</p>
{% endif %}
Question.get_poll_question()?