Reputation: 55
I want to pass data from 'About' model to html template, but I can't figure out what is going wrong.. as I am new to Django. I gave lot of time to it.. but it still remains the same:
from django.db import models
class About(models.Model):
image = models.ImageField(upload_to = 'pics')
desc = models.TextField()
views.py
from django.shortcuts import render
from .models import About
def index(request):
abt = About.objects.all()
return render(request,'home/index.html',{abt:'abt'})
html
<img src="{{abt.image}" alt="profile photo">
<p>{{abt.desc}}</p>
Upvotes: 0
Views: 105
Reputation: 1385
{abt:'abt'}
No, it's other way around.
{'abt':abt}
Label on the left, data on the right.
If you want to get a single instance you can use first
method
<p>{{abt.first.desc}}</p>
or in the similar way, provide only the first object
return render(request,'home/index.html',{'abt': abt.first()})
Upvotes: 1