update: modified the urls in buttons to open the correct URL for the new forum post

parent 8d4a32ff
......@@ -9,10 +9,10 @@
{% for post in posts_list %}
<li><a href="{% url 'forum:detail' post.id %}">{{ post.post_title }}</a> by {{ post.author.first_name }} {{ post.author.last_name}} dated {{ post.pub_date|date:"SHORT_DATE_FORMAT" }}</li>
{% endfor %}
<button onclick="location.href = '/posts/add'">New Forum Post</button>
<button onclick="location.href = '/forum/posts/add'">New Forum Post</button>
</ul>
{% else %}
<p>No posts are available.</p>
<button onclick="location.href = '/posts/add'">New Forum Post</button>
<button onclick="location.href = '/forum/posts/add'">New Forum Post</button>
{% endif %}
{% endblock %}
\ No newline at end of file
......@@ -7,7 +7,7 @@
<h1>NEW FORUM POST</h1>
</div>
<div style = "position: relative; left:80px; top:30px;">
<form method="POST" action ="{% url 'forum:add' %}" enctype="multipart/form-data">
<form method="POST" action ="{% url 'forum:post_add' %}" enctype="multipart/form-data">
{% csrf_token %}
{{ post_form.as_p }}
<button class="button" type="Save Post">Save Post</button>
......
from django.urls import path
from . import views
app_name = "forum"
app_name = 'forum'
urlpatterns = [
path('', views.index, name="index"),
path('', views.ForumView.as_view(), name="index"),
path('posts/<int:post_id>/details/', views.detail, name="detail"),
path('posts/add/', views.add, name="post_add"),
# path('welcome', views.welcome, name='welcome')
path('welcome', views.welcome, name='welcome')
]
\ No newline at end of file
from django.shortcuts import render, redirect
from django.http import HttpResponse, Http404
from django.template import loader
from django.views import View
from .models import Post, Reply
from .forms import PostForm
# Create your views here.
def index(request):
posts_list = Post.objects.order_by("pub_date")
template = loader.get_template("forum/index.html")
context = {
"posts_list": posts_list,
}
return HttpResponse(template.render(context, request))
def welcome(request):
return HttpResponse('Welcome to Widget Forum!')
class ForumView(View):
def get(self, request):
posts_list = Post.objects.order_by("pub_date")
return render(request, "forum/index.html", {"posts_list": posts_list})
def detail(request, post_id):
try:
......
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