Update the def index and add a new def detail

parent d71a766a
from django.http import HttpResponse from urllib import response
from django.http import HttpResponse, Http404
from django.shortcuts import render
from forum.models import Post from forum.models import Post
from forum.models import Reply from forum.models import Reply
# Create your views here. # Create your views here.
def index(request): def index(request):
post_objects = Post.objects.all()
post_list = Post.objects.order_by("pub_date")
context = {
"post_list": post_list
}
return render(request, "forum/index.html", context)
def details (request, post_id):
reply_list = Reply.objects.order_by("pub_date")
#error handling
try:
posts = Post.objects.get(pk=post_id)
except Post.DoesNotExist:
raise Http404("Post does not exist.")
return render(request, "forum/details.html", {"posts":posts, 'reply_list':reply_list})
"""post_objects = Post.objects.all()
reply_objects = Reply.objects.all() reply_objects = Reply.objects.all()
response = "FORUM POSTS:" response = "FORUM POSTS:"
...@@ -18,4 +41,5 @@ def index(request): ...@@ -18,4 +41,5 @@ def index(request):
+ f"{reply.author.first_name} {reply.author.last_name} " + f"{reply.author.first_name} {reply.author.last_name} "
+ f"dated {reply.pub_date.date()}:<br> {reply.reply_body} <br>") + f"dated {reply.pub_date.date()}:<br> {reply.reply_body} <br>")
return HttpResponse(response) return HttpResponse(response)"""
\ No newline at end of file
\ 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