add template for Forum post details, add static files, linked in urls

parent 9d067069
body {
padding: 64px 160px;
}
#thumbnail {
width: 150px;
height: 150px;
object-fit: cover;
object-position: center;
margin: 0 0 16px;
}
#title {
margin: 0 0 16px;
}
#subtitle {
margin: 0 0 32px;
}
.body-text {
margin: 0 0 64px;
width: 80%;
}
.replies {
padding: 0;
}
.replies > li {
margin: 0 0 16px;
width: 60%;
}
\ No newline at end of file
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;700&family=Montserrat:ital,wght@0,100;0,200;0,300;0,500;0,700;0,800;0,900;1,400;1,500&display=swap');
* {
font-family: 'Inter', sans-serif;
}
html,
body {
margin: 0;
}
h1 {
font-size: 61.04px;
}
h2 {
font-size: 48.83px;
}
h3 {
font-size: 39.06px;
}
h4 {
font-size: 31.25px;
}
h5 {
font-size: 25.00px;
}
h6 {
font-size: 16.00px;
}
:root {
font-size: 16.00px;
}
\ No newline at end of file
{% extends "base.html" %}
{% load static %}
{% block styles %}
<link rel="stylesheet" type="text/css" href="{% static 'Forum/styles.css' %}">
<link rel="stylesheet" type="text/css" href="{% static 'Forum/details.css' %}">
{% endblock %}
{% block title %}
{{ post.post_title }}
{% endblock %}
{% block content %}
<article>
<img id="thumbnail" src="{% static 'Forum/thumbnail.jpg' %}" alt="placeholder image" />
<h1 id="title">{{ post.post_title }}</h1>
<h4 id="subtitle">by {{ post.author.first_name }} {{ post.author.last_name }}, {{ post.pub_date|date:"m/d/Y" }}</h4>
<p class="body-text">{{ post.post_body }}</p>
<ul class="replies">
{% for reply in post.reply_set.all %}
<li><strong>{{ reply.author.first_name }} {{ reply.author.last_name }}, {{ reply.pub_date|date:"m/d/Y" }}:</strong> {{ reply.reply_body }}</li>
{% endfor %}
</ul>
</article>
{% endblock %}
\ No newline at end of file
from django.http import HttpResponse from django.http import HttpResponse, Http404
from django.shortcuts import render
from .models import Post, Reply from .models import Post, Reply
def get_readable_time(timestamp): def get_readable_time(timestamp):
...@@ -22,3 +23,10 @@ def index(request): ...@@ -22,3 +23,10 @@ def index(request):
out += '<br />' out += '<br />'
return HttpResponse(out) return HttpResponse(out)
def details(request, post_id):
try:
post = Post.objects.get(pk=post_id)
except Post.DoesNotExist:
raise Http404('Post does not exist')
return render(request, 'Forum/details.html', {'post': post})
\ No newline at end of file
...@@ -15,10 +15,12 @@ Including another URLconf ...@@ -15,10 +15,12 @@ Including another URLconf
""" """
from django.contrib import admin from django.contrib import admin
from django.urls import path, include from django.urls import path, include
import Forum.views as Forum_views
urlpatterns = [ urlpatterns = [
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
path('forum/', include('Forum.urls', namespace='Forum')), path('forum/', include('Forum.urls', namespace='Forum')),
path('posts/<int:post_id>/details/', Forum_views.details, name='post_details'),
path('homepage/', include('Homepage.urls', namespace="Homepage")), path('homepage/', include('Homepage.urls', namespace="Homepage")),
path('announcements/', include('Announcements.urls', namespace="Announcements")), path('announcements/', include('Announcements.urls', namespace="Announcements")),
path('assignments/', include('Assignments.urls', namespace="Assignments")), path('assignments/', include('Assignments.urls', namespace="Assignments")),
......
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