我很难从应该有图像的数据库中访问数据。
我如何访问它们,然后将它们渲染到模板中。
#models.py
class Pic(models.Model):
image = models.ImageField(upload_to='cover/pdfs', null=True, blank = True)
#forms.py
class ImageForm(forms.ModelForm):
class Meta:
model= Pic
fields= "__all__"
#views.py
def dash(request):
try:
_id = request.session['client']['id']
except:
return redirect("/loginPg")
userBio = Bio.objects.get(userData = User.objects.get(id = request.session['client']['id']))
theUploads = Pic.objects.all()
print("This image object -", theUploads)
#for pic in theUploads:
#print("MyPc", pic["image"])
content = {
"title" : userBio.title,
"qA" : userBio.quoteA,
"qB" : userBio.quoteB,
"desc" : userBio.desc,
"authorA" : userBio.authorA,
"authorB" : userBio.authorB,
"pictures" : theUploads
}
return render(request, "GoEnigma/dashboard.html", content)
我听说过Pillow,也看过相关文件。我不清楚这将如何帮助解决问题。如果对此有任何想法,我很乐意接受。