def index(request):
"""Начальная страница"""
post = Post.objects.order_by("-id")
comment = Comment.objects.all()[:3]
try:
comment_post_id = Comment.objects.filter(comment_id="1")
except Exception as er:
comment_post_id = None
return render(request, 'main/index.html', {"post": post, "comment": comment, "comment_post_id": comment_post_id})
{% extends 'main/loaut.html' %}
{% block content %}
<main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pb-2 mb-3 border-bottom">
<h1 class="h2">Главная</h1>
</div>
<div class="container">
{% if post %}
{% for i in post %}
<div class="row no-gutters border rounded overflow-hidden flex-md-row mb-4 shadow-sm h-md-250 position-relative bg-light">
<div class="col-auto d-none d-lg-block">
<img class="bd-placeholder-img" src="../../static/main/img{{ i.image.url }}" width="500" height="450">
</div>
<div class="col p-4 d-flex flex-column position-static">
<strong class="d-inline-block mb-2 text-primary">{{ i.title }}</strong>
<h3 class="mb-4">{{ i.Anons }}</h3>
{% for j in comment %}
{% if i.id|slugify == j.comment_id%}
<div class="mb-1" style="color: #27ae60">{{ j.name }}</div>
<p class="card-text mb-auto text-muted">{{ j.body }}</p>
{% else %}
<p class="card-text mb-auto text-muted"></p>
{% endif %}
{% endfor %}
<a href="{{i.id}}" class="btn btn-primary">Добавить комментарий </a>
</div></div>
{% endfor %}
{% else%}
<div class="row no-gutters border rounded overflow-hidden flex-md-row mb-4 shadow-sm h-md-250 position-relative bg-light">
<p class="mb-1" >Постов еще нет!</p>
</div>
{% endif %}
</div>
</div>
</main>
{% endblock content %}
for event in longpoll.listen():
if event.type == VkBotEventType.MESSAGE_NEW:
if event.obj.attachments != []:
if event.obj.attachments[0]['type'] == 'photo':
....
elif event.obj.attachments[0]['type'] == 'wall':
....
elif event.obj.attachments[0]['type'] == 'video':