'How to create multiple pages if there were too many for one page?
I'm working on a django project trying to create a forum. Now when a certain number of objects (thread-previews) is reached on one page, I want a second (and then third page etc) page created and some of these objects should go to these next pages (page 2, then page 3 etc.) and the url for the second page should be something like "mysite.com/fourum/topic/2" and so on.
And then there have to be some buttons to navigate to page 2, page 3 etc.
This would be relevant code:
gaming.html
{% extends "forum/index.html" %}
{% load static %}
{% block title %} Gaming {% endblock %}
{% block content %}
<div class="main-container">
<h1 class="heading">Forum: Gaming</h1>
{% for obj in object %}
<div class="username">{{obj.username}}</div>
<div class="date">{{obj.date}}</div>
<div class="topic">{{obj.topic}}</div>
<div class="title"><a class="link" href="{{obj.slug_titel}}">{{obj.title}}</a></div>
<div class="content">{{obj.content}}</div>
{% endfor %}
</div>
{% endblock %}
views.py
def gaming(request):
obj = Threads.objects.filter(topic="gaming")
context = {
"object": obj,
}
return render(request, "forum/gaming.html", context)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
