Commit 38c53623 authored by Rurik Serzo's avatar Rurik Serzo

changed index from fbv to cbv

parent e44b4009
from django.urls import path from django.urls import path
from .views import index, PostDetailView, new_post from .views import IndexView, PostDetailView, new_post
urlpatterns = [ urlpatterns = [
path("", index, name="index"), path("", IndexView.as_view(), name="index"),
path("<int:pk>/details", PostDetailView.as_view(), name="post-detail"), path("<int:pk>/details", PostDetailView.as_view(), name="post-detail"),
path("add", new_post, name="new-post") path("add", new_post, name="new-post")
] ]
......
...@@ -2,16 +2,18 @@ from django.shortcuts import render, redirect ...@@ -2,16 +2,18 @@ from django.shortcuts import render, redirect
from django.http import HttpResponse from django.http import HttpResponse
from django.template import loader from django.template import loader
from django.views.generic.detail import DetailView from django.views.generic.detail import DetailView
from django.views.generic.base import TemplateView
from .models import Post, Reply from .models import Post, Reply
from .forms import PostForm from .forms import PostForm
def index(request): class IndexView(TemplateView):
context = { def get(self, request):
"posts": Post.objects.order_by("-pub_date"), context = {
} "posts": Post.objects.order_by("-pub_date"),
template = loader.get_template("forum/index.html") }
return HttpResponse(template.render(context, request)) template = loader.get_template("forum/index.html")
return HttpResponse(template.render(context, request))
class PostDetailView(DetailView): class PostDetailView(DetailView):
model = Post model = Post
......
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