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,11 +2,13 @@ from django.shortcuts import render, redirect ...@@ -2,11 +2,13 @@ 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):
def get(self, request):
context = { context = {
"posts": Post.objects.order_by("-pub_date"), "posts": Post.objects.order_by("-pub_date"),
} }
......
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