feat: added new method to views, defining the process in which a valid post form is added

parent 2231a039
......@@ -7,7 +7,7 @@
<h1>NEW FORUM POST</h1>
</div>
<div style = "position: relative; left:80px; top:30px;">
<form method="POST" action ="{% url 'homepage:add' %}" enctype="multipart/form-data">
<form method="POST" action ="{% url 'forum:add' %}" enctype="multipart/form-data">
{% csrf_token %}
{{ user_form.as_p }}
<button class="button" type="Save Post">Save Post</button>
......
......@@ -2,6 +2,7 @@ from django.shortcuts import render, redirect
from django.http import HttpResponse, Http404
from django.template import loader
from .models import Post, Reply
from .forms import PostForm
# Create your views here.
def index(request):
......@@ -21,4 +22,11 @@ def detail(request, post_id):
return render(request, "forum/detail.html", {"post": post, "reply": reply})
def add(request):
if request.method == "POST":
post_form = PostForm(request.POST, request.FILES)
if post_form.is_valid():
post_form.save()
return redirect("/forum")
else:
post_form = PostForm()
return render(request, "forum/add.html", {"post_form": post_form})
\ 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