Displaying multiple images to a blog post in Django -
i want display multiple images body of blog post. i'll upload images through admin page.
# 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) 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 %}
the body of post like:
<h2>example blog post</h2> <p>here text. , image part:</p> <img src="{{ post.image1.filename }}" alt="{{ post.image1.description }}" /> <p>here other text , image part:</p> <img src="{{ post.image2.filename }}" alt="{{ post.image2.description }}" /> <p>i'm ending blog post here.</p>
clearly, code above incorrect guess explains want do.
i'm aware django-ckeditor supports this. don't prefer use ckeditor.
i found couple videos explaining adding single images (like this or this), guess can handle. not find method insert images when there might 1 or more images given blog post. this helpful more uploading not inserting images.
Comments
Post a Comment