Commit 9adb11a1 authored by Cherish Magpayo's avatar Cherish Magpayo

Add announcements detail view and modify announcements index to use html template

parent f81a0da8
from django.http import HttpResponse from django.http import HttpResponse, Http404
from django.shortcuts import render
from announcements.models import Announcement from announcements.models import Announcement
# Create your views here. # Create your views here.
def index(request): def index(request):
announcement_list = Announcement.objects.order_by("pub_date")
context = {
"announcement_list": announcement_list,
}
return render(request, "announcements/index.html", context)
def details(request, announcement_id):
try:
announcement = Announcement.objects.get(pk=announcement_id)
except Announcement.DoesNotExist:
raise Http404("Announcement does not exist!")
return render(request, "announcements/details.html", {"announcement": announcement})
""" midterms
announcement_objects = Announcement.objects.all() announcement_objects = Announcement.objects.all()
response = "ANNOUNCEMENTS:<br>" response = "ANNOUNCEMENTS:<br>"
...@@ -18,3 +37,4 @@ def index(request): ...@@ -18,3 +37,4 @@ def index(request):
+ f"Like: {like} <br> Love: {love} <br> Angry: {angry}<br><br>") + f"Like: {like} <br> Love: {love} <br> Angry: {angry}<br><br>")
return HttpResponse(response) return HttpResponse(response)
"""
\ 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