DEV Community

Zeeshan Tariq
Zeeshan Tariq

Posted on

Django model data does not show in template

models.py

from django.db import models

class ToDo(models.Model):
title = models.CharField(max_length=100)
detail = models.TextField()
published_date = models.DateTimeField()

def __str__(self):
    return self.title

Views.py

from django.shortcuts import render, HttpResponse, redirect
from django.utils import timezone
from todoapp.models import ToDo

Create your views here.

def home(request):
todo_items = ToDo.objects.all()
context = {'todoItems': todo_items}
return render(request, 'todoapp/home.html', context)

def add(request):
if request.method=="POST":
addTitle = request.POST['addTitle']
addDetail = request.POST['addDetail']
current_date = timezone.now()

    addedObject = ToDo.objects.create(title=addTitle, detail=addDetail, published_date=current_date)
    return redirect('home')


return render(request, 'todoapp/home.html')

Top comments (2)

Collapse
 
highcenburg profile image
Vicente G. Reyes

Could you post your code on the template?

Collapse
 
zeeshantariqpkn profile image
Zeeshan Tariq

Liquid syntax error: Unknown tag 'load'