title: How To Fix name 'post' is not defined in django in comment
body: <p>How To Fix name 'post' is not defined in django in comment when i comment in my django website then if i disapprove comment i get this error:</p>
  
  <pre><code>NameError at /comment/1/remove/
  name 'post' is not defined
  </code></pre>
  
  <p>i want to reject comment but i get error please help me i'm wating for you!</p>
  
  <p>Here is my app <strong>Urls.py</strong></p>
  
  <pre><code>from django.urls import path,re_path
  from blog import views
  
  urlpatterns = [
      path('',views.PostListView.as_view(),name='post_list'),
      path('about/',views.AboutView.as_view(),name='about'),
      path('register/',views.user_register,name='user_register'),
      path('post/&lt;int:pk&gt;',views.PostDetailView.as_view(),name='post_detail'),
      path('post/new/',views.CreatePostView.as_view(),name='post_new'),
      path('post/&lt;int:pk&gt;/edit/',views.PostUpdateView.as_view(),name='post_edit'),
      path('post/&lt;int:pk&gt;/remove/',views.PostDeleteView.as_view(),name='post_remove'),
      path('drafts/',views.PostDraftListView.as_view(),name='post_draft_list'),
      re_path('^post/(?P&lt;pk&gt;\d+)/comment/$',views.add_comment_to_post,name='add_comment_to_post'),
      path('comment/&lt;int:pk&gt;/approve/',views.comment_approve,name='comment_approve'),
      path('comment/&lt;int:pk&gt;/remove/',views.comment_remove,name='comment_remove'),
      path('post/&lt;int:pk&gt;/publish/',views.post_publish,name='post_publish'),
  ]
  </code></pre>
  
  <p>Here is my <strong>views.py</strong></p>
  
  <pre><code>from django.shortcuts import render , get_object_or_404,redirect
  from django.utils import timezone
  from blog.models import *
  from blog.forms import *
  from django.contrib.auth.decorators import login_required
  from django.urls import reverse_lazy
  from django.contrib.auth.models import User
  from django.contrib.auth.mixins import LoginRequiredMixin
  from django.views.generic import (TemplateView,ListView,
                                      DetailView,CreateView,
                                      UpdateView,DeleteView)
  # Create your views here.\
  #......................
  ##########################
  ##########################
  
  @login_required
  def post_publish(request,pk):
      post = get_object_or_404(Post,pk=pk)
      post.publish()
      return redirect('post_detail',pk=pk)
  
  
  @login_required
  def add_comment_to_post(request,pk):
      post = get_object_or_404(Post,pk=pk)
      if request.method == 'POST':
          form = CommentForm(request.POST)
          if form.is_valid():
              comment = form.save(commit=False)
              comment.post = post
              comment.save()
              return redirect('post_detail',pk=post.pk)
      else:
          form = CommentForm()
      return render(request,'blog/comment_form.html',{'form':form})
  
  @login_required
  def comment_approve(request,pk):
      comment = get_object_or_404(Comment,pk=pk)
      comment.approve()
      return redirect('post_detail',pk=comment.post.pk)
  
  @login_required
  def comment_remove(request,pk):
      comment = get_object_or_404(Comment,pk=pk)
      post_pk = comment.post.pk
      comment.delete()
      return redirect('post_detail',pk=post.pk)
  </code></pre>
  
  <p>Here is my <strong>Models.py</strong></p>
  
  <pre><code>class Comment(models.Model):
      post = models.ForeignKey('blog.Post',related_name='comments',on_delete="Cascade")
      author = models.CharField(max_length=200)
      text = models.TextField()
      created_date = models.DateTimeField(default=timezone.now())
      approved_comment = models.BooleanField(default=False)
  
      def approve(self):
          self.approved_comment = True
          self.save()
  
      def get_absolute_url(self):
          #need to add reverse because reverse is not importing # post_detail
          return revrse("post_list")
  
      def __str__(self):
          return self.text
  </code></pre>
  
  <p>Here is my <strong>Forms.py</strong></p>
  
  <pre><code>class CommentForm(forms.ModelForm):
  
      class Meta():
          model = Comment
          fields = ('author','text')
          widgets = {
              'author':forms.TextInput(attrs={'class':'textinputclass'}),
              'text':forms.Textarea(attrs={'class':'editable medium-editor-textarea'}),
              }
  </code></pre>
  
  <p>Here is my <strong>comment_form.html</strong></p>
  
  <pre><code>{% extends "blog/base.html" %}
  {% block content %}
  &lt;h1&gt;New Comment&lt;/h1&gt;
  &lt;form class="post-form" method="POST"&gt;
      {% csrf_token %}
      {{ form.as_p }}
      &lt;button type="submit" class="save btn btn-default"&gt;Post Comment&lt;/button&gt;
  &lt;/form&gt;
  &lt;script&gt;var editor = new MediumEditor('.editable');&lt;/script&gt;
  {% endblock %}
  </code></pre>