Commit 26331164 authored by Rurik Serzo's avatar Rurik Serzo

Added template for forum index

parent 66a3d8f6
{% extends 'base.html' %}
{% load static %}
{% block title %}Forum{% endblock %}
{% block styles %}
<link rel="stylesheet" href="{% static 'forum.css' %}">
{% endblock %}
{% block content %}
<h1 class="forum-heading">Welcome to Widget's Forum</h1>
<h2 class="forum-subheading">Forum posts:</h2>
<ul class="post-list">
{% for post in posts %}
<li>
<a href="/forum/{{ post.id }}/details">
{{ post.post_title }} by {{ post.author.first_name }} {{ post.author.last_name }}
dated {{ post.pub_date|date:'d/m/Y' }}
</a>
</li>
{% endfor %}
</ul>
{% endblock %}
\ No newline at end of file
from django.shortcuts import render
from django.http import HttpResponse
from django.template import loader
from .models import Post, Reply
def index(request):
posts = Post.objects.all()
formatted_posts = "FORUM POSTS:<br>"
for post in posts:
formatted_posts += post.getPost()
replies = Reply.objects.all().filter(post__post_title=post)
for reply in replies:
formatted_posts += reply.getReply()
formatted_posts += "<br>"
return HttpResponse(formatted_posts)
context = {
"posts": Post.objects.order_by("-pub_date"),
}
template = loader.get_template("forum/index.html")
return HttpResponse(template.render(context, request))
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment