Add redirect to page 1 from bare URL
Previously, you could browse /board/ and /board/page/1/ in the browser and they would be the same thing. Now, /board/ redirects to /board/page/1/ to keep things unambiguous. Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -3,6 +3,7 @@ from django.http import Http404, HttpResponseRedirect
|
||||
from django.shortcuts import render, get_object_or_404
|
||||
from django.views.generic import DetailView
|
||||
from django.views.generic.edit import CreateView
|
||||
from django.urls import reverse
|
||||
from board.models import Post, Board
|
||||
from board.forms import PostForm, ReplyForm
|
||||
|
||||
@@ -54,8 +55,16 @@ class BoardView(CreatePostView):
|
||||
slug_url_kwarg = "url"
|
||||
template_name = "board/board_detail.html"
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
# If the page isn't set, then redirect to the /page/1 url
|
||||
if "page" not in kwargs:
|
||||
return HttpResponseRedirect(
|
||||
reverse("board:board_detail", kwargs={"url": kwargs["url"], "page": 1})
|
||||
)
|
||||
return super(BoardView, self).get(request, *args, **kwargs)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
page = self.kwargs.get("page", 1)
|
||||
page = self.kwargs["page"]
|
||||
|
||||
if page not in range(1, self.board.max_pages + 1):
|
||||
raise Http404()
|
||||
|
||||
Reference in New Issue
Block a user