title: how to fix "NameError: name 'context' is not defined"
body: <p>I want to use ajax in comments and reply sections of my blog application. In function based view everything is working fine, but I want to do it class based view. </p>
  
  <pre><code>***My function based view***
  def post_detail(request, pk):
      post = get_object_or_404(Post, pk=pk)
      comments = Comment.objects.filter(post=post, reply=None).order_by('-id')
      if request.method == 'POST':
          comment_form = CommentForm(request.POST or None)
          if comment_form.is_valid():
              content = request.POST.get('content')
              reply_id = request.POST.get('comment_id')
              comment_qs = None
              if reply_id:
                  comment_qs = Comment.objects.get(id=reply_id)
  
              comment = Comment.objects.create(post=post,
                                               user=request.user,
                                               content=content,
                                               reply=comment_qs)
              comment.save()
  
      else:
          comment_form = CommentForm()
      context = {
          'title': 'blog',
          'post': post,
          'comments': comments,
          'comment_form': comment_form,
      }
      if request.is_ajax():
          html = render_to_string('blog/comments.html', context, request=request)
          return JsonResponse({'form': html})
  
      return render(request, 'blog/post_detail.html', context)
  
  ***My class based view***
  class PostDetailView(FormMixin, DetailView):
      model = Post
      form_class = CommentForm
  
      def get_context_data(self, **kwargs):
          context = super().get_context_data(**kwargs)
          post = get_object_or_404(Post, id=self.object.id)
          comments = Comment.objects.filter(post=post, reply=None).order_by('-id')
          context['title'] = 'Blog Detail'
          context['comments'] = comments
          context['comment_form'] = self.get_form()
          return context
  
      def post(self, request, *args, **kwargs):
          #if request.user.is_authenticated():
  
          self.object = self.get_object()
          form = self.get_form()
          if form.is_valid():
              content = request.POST.get('content')
              reply_id = request.POST.get('comment_id')
              comment_qs = None
              if reply_id:
                  comment_qs = Comment.objects.get(id=reply_id)
              comment = Comment.objects.create(post=self.object,
                                               user=request.user,
                                               content=content,
                                               reply=comment_qs)
              comment.save()
              #return HttpResponseRedirect(self.object.get_absolute_url())
          else:
              return self.form_invalid(form)
  
          if request.is_ajax():
              html = render_to_string('blog/comments.html', context, request=request)
              return JsonResponse({'form': html})
  
      def get_success_url(self):
          return reverse('post-detail', kwargs={'pk': self.kwargs['pk'], })
  </code></pre>
  
  <p>In my class based view in <code>if request.is_ajax():
                  html = render_to_string('blog/comments.html', context,request=request)
                  return JsonResponse({'form': html})</code> 
  part it shows the error that context is not defined. So how to fix this problem or how to include it in function, since I have already context. 
  There is no problem in my function based view code it is working as expected. </p>