I'm a complete beginner in Django, now after reading some articles I've managed to build a blog in Django where I can post (all through the Django administration). However, I also wanted to be able to add an image to my post, so I created an image field in my model, now it is also possible to upload images through the Django administration, these are then stored in the media/images folder. However, until now (after reading some articles) I haven't managed to display these pictures in my blog posts.
Please excuse the probably a little stupid question and thanks a lot for the help
Bennet
My models.py file
from django.db import models
# Create your models here.
class Post(models.Model):
title = models.CharField(max_length= 255)
slug = models.SlugField()
intro = models.TextField()
body = models.TextField()
image = models.ImageField(upload_to='images/')
date_added = models.DateTimeField(auto_now_add=True)
def __str__(self):
return self.title
class Meta:
ordering = ['-date_added']
the page where I want to display the image
{% block content %}
<div class="section title is-size-5 has-text-centered">
<div class="title">{{post.title}}</div>
<div class="subtitle">{{post.date_added}}</div>
</div>
<div class="container">
<div class="columns">
<div class="column is-8 is-offset-2">
<div class="blob">
<img src="{{post.image}}" alt="">
{{post.body}}
</div>
</div>
</div>
</div>
{% endblock content %}