I'm creating private messages application, and I render my messages this way:
return render(request,'mssg/mssg_page.html', {'inbox':inbox, 'current_mssg':current_mssg,})
Inbox contain all messages. Current message is a one that should be fully displayed. I made a list of messages that look like this in my template:
{% for mssg in inbox %}
<a href="#"><!-- here -->
<div class="right">
<h3>{{ mssg.mssg_from.username }} <small>{{ mssg.delivery_date }}</small></h3>
<h2>{{ mssg.title|safe }}</h2>
<p>{{ mssg.text|safe|truncatewords:15 }}</p>
</div>
</a>
{% endfor %}
I display full current message in same template too.
I wants to change current message after clicking on link with <!-- here -->
commment
I know that I can send message id to view, validate it and send it back to template. But it needs page to be refreshed. However all messages are already in template listed in inbox
so there should be no need to refresh page. I also know that it's possible to pick an message from inbox like this {{inbox.0}}
But I have no idea how to make it depended on clicked link. I guess that javascript is needed for it. But I even if I know that I can do something like inbox[0]
by placing inbox.0
in template I still don't know how to do something like inbox[varriable]
.
Is there a way to do it?
I don't want my page to refresh if it don't have to do it.
PS I'm using bootsrap