all bojects have been successfully save in admin dashboard but do not receive dynamic data in index.html page from admin dasboard. please any one can be help me.
**views.py**
from django.shortcuts import render
from .models import home
# Create your views here.
def home(request):
homeobject = home.objects.all()
return render(request, 'index.html', {'homes': homeobject})
**models.py**
class home(models.Model):
HOME_CATEGORY = [
('SR', 'Service'),
('VL', 'Vlog'),
('CR', 'course'),
]
title = models.CharField(max_length=120)
description = models.TextField()
image = models.ImageField(upload_to='images')
home_category = models.CharField(max_length=2, choices=HOME_CATEGORY)
**index.html**
{% for home in homes %}
{{home}}
{% endfor %}
CodePudding user response:
your view function name is defined as home
and your model is named home
you define home
as a function so when you go to access home.objects
python does not see your model home
but the function home
Change the class name of model from home
to Home
and do migrations - migrate . Also don't forget to change in query Home.objects.all()
index.html
{% for home in homes %}
<h1> {{home.title}} </h1>
<p> {{home.description}} </p>
<img src={{home.image.url}} />
{% endfor %}