title: Django: Use ajax to add an HTML element
body: <p>I've researched this topic for quite some time, but I just can't seem to find the answer or explanation I'm looking for. I have a Django app with a discussion board (similar to Facebook's timeline), and I want to know how to use ajax to make a new post or comment on someone's post.</p>
  
  <p>Here is the template code:</p>
  
  <pre><code>&lt;form action='/create_post/' method="post" id="post-form"&gt;
        {% csrf_token %}
  
        {% render_field post_form.body id="post-text" class+="form-control" rows="4" placeholder="Say howdy to your neighbors!" %}
        &lt;div id="comment-row" class="row"&gt;
          &lt;button id="post-submit" type="submit" name="submit" class="btn btn-primary"&gt;Post&lt;/button&gt;
        &lt;/div&gt;
      &lt;/form&gt;
  </code></pre>
  
  <p>Here is the "create_post" view:</p>
  
  <pre><code>def create_post(request):
      if request.POST:
         # get POST data
         body = request.POST['body']
         author = request.user
         apartment_id = author.tenant.apartment.id
  
         # create new Post
         post = Post(body=body, author=author, apartment_id=apartment_id)
         post.save()
  
         return HttpResponseRedirect('/stream/')
     else:
         return HttpResponse('&lt;p&gt;here&lt;/p&gt;')
  </code></pre>
  
  <p>and the <code>return HttpResponseRedirect('/stream/</code>) calls:</p>
  
  <pre><code>def stream(request):
     # get data to pass to template
     user = request.user
     post_form = PostForm()
     comment_form = CommentForm()
     apartment_id = user.tenant.apartment.id
     posts = Post.objects.filter(apartment_id=apartment_id).order_by('-id')
     comments = Comment.objects.all().order_by('id')
  
     return render(request, 'stream/stream.html', {
         'user': user,
         'post_form': post_form,
         'comment_form': comment_form,
         'posts': posts,
         'comments': comments,
     })
  </code></pre>
  
  <p>where this renders a template that renders each post with each comment.</p>
  
  <p>Is there some sort of way to simply re-render the '/stream/' template (which would include the new post) without refreshing the page? That seems like the cleanest way to do it to me. Does the django-ajax package do this? Because if so, I could not get it to work. If not, what is the cleanest/'right' way to do this?</p>
  
  <p>Thanks.</p>