title: Django ajax comments using Jquery?
body: <p>I want to implement a ajax commenting system. </p>
  
  <p>urls.py:</p>
  
  <pre><code>(r'^comment/(\d+)/$', comments),
  </code></pre>
  
  <p>views.py:</p>
  
  <pre><code>def comments(request,feed):
    if request.method == 'POST':
      feed=Feed.objects.get(pk=feed)
      form = CommentForm(request.POST)
      if form.is_valid():
         comment, created = Comment.objects.get_or_create(
            feed=feed,
            msg=form.cleaned_data['msg'],
            ip=request.META['REMOTE_ADDR']
          )
  
      comments=Comment.objects.filter(feed=feed)
      form=CommentForm()
      variables=RequestContext(request,{'comments': comments,'feed': feed,'form':form,})
      if 'HTTP_REFERER' in request.META:
        return HttpResponseRedirect(request.META['HTTP_REFERER'])
      return render_to_response('comment_page.html', variables )
      #return HttpResponseRedirect('/view/')
    else:
      form=CommentForm()
      feed=Feed.objects.get(pk=feed)
      comments=Comment.objects.filter(feed=feed).reverse()
  
  
      variables=RequestContext(request,{'comments': comments,'feed': feed,'form':form,})
      return render_to_response('comment_page.html', variables )
  </code></pre>
  
  <p>Templates:</p>
  
  <pre><code>&lt;div id="commentbox" style="display:none;"&gt;
        &lt;form class="comment" method="post" action="/comment/{{feed.id}}/"&gt;
                 {{cform.as_p}}
                 &lt;input class="post" type="submit" value="post" /&gt;
                 &lt;/form&gt;
                &lt;/div&gt;
                &lt;/br&gt;
                &lt;h3&gt;&lt;/h3&gt;&lt;button class="ccc"&gt;Show/Hide Comment&lt;/button&gt; {{feed.comment_set.count}} Comments
                &lt;div id="commentlist" class="commentlist" style="padding-left:10px;"&gt;&lt;ul style="list-style-type:square;"&gt;
                {% for c in feed.comment_set.all %}
  
                &lt;li&gt;{{c.msg}}&lt;/li&gt;
  
                {% endfor %}
                &lt;/ul&gt;
                &lt;/div&gt;
  </code></pre>
  
  <p>What code should I include to add comments into commentlist li field without page refresh. I am new in ajax. Please help. Thanks</p>