I think it has something to do with my urls.py and views.py

*urls.py*
from django.urls import path
from .views import (
    PostListView,
    PostDetailView,
    PostCreateView,
    PostUpdateView,
    PostDeleteView,
    UserPostListView,
    UserProfileListView,
    UserProfilePostListView
)
from . import views


urlpatterns = [
    path('', PostListView.as_view(), name='blog-home'),
    path('user/<str:username>/', UserProfileListView.as_view(), name=
'user-profile' ),
    path('user/<str:username>/posts/', UserPostListView.as_view(), name=
'user-posts'),
    path('user/<str:username>/posts/view/', UserProfilePostListView.as_view
(), name='user-posts-view'),
    path('post/<int:pk>/', PostDetailView.as_view(), name='post-detail'),
    path('post/<int:pk>/comment/', views.add_comment, name='add-comment'),
    path('post/new', PostCreateView.as_view(), name='post-create'),
    path('post/<int:pk>/edit/', PostUpdateView.as_view(), name='post-update'
),
    path('post/<int:pk>/delete/', PostDeleteView.as_view(), name=
'post-delete'),
    path('about/', views.about, name='blog-about')
]

views.py
*from django.shortcuts import render, get_object_or_404*
*from django.contrib.auth.mixins import LoginRequiredMixin, 
UserPassesTestMixin*
*from django.contrib.auth.models import User*
*from django.views.generic import ListView, DetailView, CreateView, 
UpdateView, DeleteView*
*from .models import Post*


*def home(request):*
*    context = {*
*        'posts': Post.objects.all()*
*    }*
*    return render(request, 'blog/home.html', context)*

*def upsite(request):*
*    context = {*
*        'uposts': UPost.objects.all()*
*    }*


*class PostListView(ListView):*
*    model = Post*
*    template_name = 'blog/home.html'*
*    context_object_name = 'posts'*
*    ordering =['-date_posted']*
*    paginate_by = 5*


*class UserPostListView(ListView):*
*    model = Post*
*    template_name = 'blog/user_posts.html'*
*    context_object_name = 'posts'*
*    paginate_by = 5*

*    def get_queryset(self):*
*        user = get_object_or_404(User, 
username=self.kwargs.get('username'))*
*        return Post.objects.filter(author=user).order_by('-date_posted')*

*class UserProfileListView(ListView):*
*    model = Post*
*    template_name = 'blog/user_profile.html'*
*    context_object_name = 'posts'*
*    paginate_by = 5*

*    def get_queryset(self):*
*        user = get_object_or_404(User, 
username=self.kwargs.get('username'))*
*        return Post.objects.filter(author=user).order_by('-date_posted')*

*class UserProfilePostListView(ListView):*
*    model = Post*
*    template_name = 'blog/user_profile_posts.html'*
*    context_object_name = 'posts'*
*    paginate_by = 5*

*    def get_queryset(self):*
*        user = get_object_or_404(User, 
username=self.kwargs.get('username'))*
*        return Post.objects.filter(author=user).order_by('-date_posted')*

*class PostDetailView(DetailView):*
*    model = Post*

*class PostCreateView(LoginRequiredMixin, CreateView):*
*    model = Post*
*    fields = ['title', 'content']*

*    def form_valid(self, form):*
*        form.instance.author = self.request.user*
*        return super().form_valid(form)*

*class PostUpdateView(LoginRequiredMixin, UserPassesTestMixin, UpdateView):*
*    model = Post*
*    fields = ['title', 'content']*

*    def form_valid(self, form):*
*        form.instance.author = self.request.user*
*        return super().form_valid(form)*

*    def test_func(self):*
*        post = self.get_object()*
*        if self.request.user == post.author:*
*            return True*
*        else:*
*            return False*

*class PostDeleteView(LoginRequiredMixin, UserPassesTestMixin, DeleteView):*
*    model = Post*
*    success_url = '/'*

*    def test_func(self):*
*        post = self.get_object()*
*        if self.request.user == post.author:*
*            return True*
*        else:*
*            return False*

*def about(request):*
*    return render(request, 'blog/about.html', {'title': 'About'})*

*def add_comment(request, slug):*
*    post = get_object_or_404(Post, slug=slug)*
*    if request.method == 'POST':*
*        form = CommentForm(request.POST)*
*        if form.is_valid():*
*            comment = form.save(commit=False)*
*            comment.post = post*
*            comment.save()*
*            return redirect('blog:post_detail', slug=post.slug)*
*    else:*
*        form = CommentForm()*
*    template = 'blog/add-comment.html'*
*    context = {*
*        'form': form*
*    }*
*    return render(request, template, context)*





-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/929751dd-b944-4e14-994e-4d0e69f1bd2d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to