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.shortcuts import render
from django.http import HttpResponse from django.http import HttpResponse
from django.template import loader
from .models import Post, Reply from .models import Post, Reply
def index(request): def index(request):
posts = Post.objects.all() context = {
formatted_posts = "FORUM POSTS:<br>" "posts": Post.objects.order_by("-pub_date"),
}
for post in posts: template = loader.get_template("forum/index.html")
formatted_posts += post.getPost() return HttpResponse(template.render(context, request))
replies = Reply.objects.all().filter(post__post_title=post) \ No newline at end of file
for reply in replies:
formatted_posts += reply.getReply()
formatted_posts += "<br>"
return HttpResponse(formatted_posts)
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