<img src="\media\images\image1.jpg" alt="My Desrciption" />
<img src="{{ post.images.image.url[1] }}" alt="{{ post.images.image.url[2] }}" />
# models.py:
class Post(models.Model):
title = models.CharField(max_length=250)
body = models.TextField()
slug = models.SlugField(max_length=250)
publish = models.DateTimeField(default=timezone.now)
class Images(models.Model):
post = models.ForeignKey(Post, default=None, related_name='images')
description = models.TextField()
image = models.ImageField()
# views.py:
def post_detail_view(request, year, month, day, postslug):
post = get_object_or_404(Post,
slug=postslug,
publish__year=year,
publish__month=month,
publish__day=day
)
return render(request=request,
template_name='blogapp/post/detail.html',
context={'post': post})
# detail.html:
{% extends "blogapp/base.html" %}
{% block title %}{{ post.title }}{% endblock %}
{% block content %}
<h1>{{ post.title }}</h1>
{{ post.body|safe }}
{% endblock %}
post.body = """
<h2>Example blog post</h2>
<p>Here is some text. And image for this part:</p>
<img src="{{ post.image1.filename }}" alt="{{ post.image1.description }}" />
<p>Here is some other text and image for this part:</p>
<img src="{{ post.image2.filename }}" alt="{{ post.image2.description }}" />
<p>I'm ending my blog post here.</p>
"""