title: Django Ajax jQuery URL
body: <p>I have the following template file, where I am going to perform an <em>ajax request</em>. If I click on the <em>show link</em> in the template the jquery function gets executed and then I receive the following <strong>error message</strong> in the developer console of my browser:</p>
  <ul>
  <li><p><code>TypeError at /projects/djangobook/discussions/5/show/8</code></p>
  </li>
  <li><p><code>'NoneType' object is not callable</code></p>
  </li>
  </ul>
  <p><strong>Traceback:</strong></p>
  <pre><code>File &quot;/Users/sebastian/Developer/Zaumdo/lib/python2.7/site-packages/django/core/handlers/base.py&quot; in get_response
    115.                         response = callback(request, *callback_args, **callback_kwargs)
  
  File &quot;/Users/sebastian/Developer/Zaumdo/lib/python2.7/site-packages/django/views/generic/base.py&quot; in view
    68.             return self.dispatch(request, *args, **kwargs)
  
  File &quot;/Users/sebastian/Developer/Zaumdo/lib/python2.7/site-packages/braces/views.py&quot; in dispatch
    107.             request, *args, **kwargs)
  
  File &quot;/Users/sebastian/Developer/Zaumdo/Zaumdo/core/mixins.py&quot; in dispatch
    49.         return super(GroupAwareMixin, self).dispatch(request, *args, **kwargs)
  
  File &quot;/Users/sebastian/Developer/Zaumdo/lib/python2.7/site-packages/django/views/generic/base.py&quot; in dispatch
    86.         return handler(request, *args, **kwargs)
  
  Exception Type: TypeError at /projects/djangobook/discussions/5/show/8
  
  Exception Value: 'NoneType' object is not callable
  
  Request information:
  GET: No GET data
  
  POST:
  name = u'sebastian'
  
  FILES: No FILES data
  
  COOKIES:
  csrftoken = 'fWD0OojhrpTLhuxtxb2NF96rVSnKGpWy'
  sessionid = 'fccuv36b538pqnulqyhbdsq7ihyrvjo5'
  </code></pre>
  <p><strong>template.html</strong></p>
  <pre><code>{% for post in object_list %}
      {{ post.creator }}
      {{ post.created }}
      {{ post.body }}
      &lt;a href=&quot;{% groupurl post_answer group discussion_id=discussion.id pk=post.id %}&quot;&gt;Answer&lt;/a&gt;
      &lt;a class=&quot;show_answers&quot; href=&quot;{% groupurl post_show_answers group discussion_id=discussion.id post_id=post.id %}&quot;&gt;Show&lt;/a&gt;
  {% endfor %}
  
  &lt;script type=&quot;text/javascript&quot;&gt;
      $(&quot;.show_answers&quot;).click(function(e) {
          e.preventDefault();
          var self = $(this);
          ajax_req = $.ajax({
              url: self.attr(&quot;href&quot;),
              type: &quot;POST&quot;,
              data: {name: &quot;sebastian&quot;},
              success: function(ctx) {console.log(ctx);}
          });
      });
  &lt;/script&gt;
  </code></pre>
  <p><strong>urls.py</strong></p>
  <pre><code>from django.conf.urls import patterns, url
  
  from discussions.views import DiscussionListView, DiscussionCreateView, DiscussionUpdateView,
  DiscussionDeleteView, PostListView, PostCreateView, PostAnswerView
  
  urlpatterns = patterns\
  (
      'discussions.views',
      url(r'^$', DiscussionListView.as_view(), name='discussion_list'),
      url(r'^create/$', DiscussionCreateView.as_view(), name='discussion_create'),
      url(r'^update/(?P&lt;pk&gt;\d+)$', DiscussionUpdateView.as_view(), name='discussion_update'),
      url(r'^delete/(?P&lt;pk&gt;\d+)$', DiscussionDeleteView.as_view(), name='discussion_delete'),
      url(r'^(?P&lt;discussion_id&gt;\d+)/$', PostListView.as_view(), name='discussion'),
      url(r'^(?P&lt;pk&gt;\d+)/create/$', PostCreateView.as_view(), name='post_create'),
      url(r'^(?P&lt;discussion_id&gt;\d+)/answer/(?P&lt;pk&gt;\d+)', PostAnswerView.as_view(), name='post_answer'),
      url(r'^(?P&lt;discussion_id&gt;\d+)/show/(?P&lt;post_id&gt;\d+)', PostListView.as_view(), name='post_show_answers'),
  )
  </code></pre>
  <p>In this view I would like to send an HttpResponse.</p>
  <p><strong>views.py</strong></p>
  <pre><code>class PostListView(LoginRequiredMixin, GroupAwareMixin, ListView):
      model = Post
      template_name = 'discussions/discussion.html'
  
      discussion = None
      post = None
      posts = None
  
      def get_queryset(self):
          # Get the discussions from the pk in the url
          self.discussion = get_object_or_404(Discussion, pk=self.kwargs['discussion_id'])
  
          # return HttpResponse(json.dumps(&quot;success&quot;), mimetype=&quot;application/json&quot;)
  
          # Fetch all the root posts (depth=1) in the discussion
          self.posts = self.discussion.posts.filter(depth=depth)
          return self.posts
  
      def get_context_data(self, **kwargs):
          context = super(PostListView, self).get_context_data(**kwargs)
          context['discussion'] = self.discussion
          return context
  </code></pre>