title: How to jump to anchor with invalid Django form?
body: <p>When my Django form fails to validate it automatically goes back to the page where the form failed but I'd like it to go to an html anchor on the page. Here's the code I have:</p>
  
  <pre><code>
  def detail(request, post_id):
      p = get_object_or_404(Post, pk=post_id)
      # get all the comments for the post
      comments = p.comment_set.all().order_by('pub_date')
      # to add a comment to the post
      if request.method=='POST':
          form = CommentForm(request.POST)
          if form.is_valid():
              c = Comment()
              c.body = request.POST['body']
              c.post = p
              c.save()
              return HttpResponseRedirect(reverse('journal.views.detail', kwargs={'post_id': post_id}) + "#comment-" + str(c.id))
      else:
          form = CommentForm()
      return render(request, 'posts/detail.html', {'post': p, 'comments': comments, 'form': form})</code></pre>
  
  <p>The form is a comment form at the bottom of a blog post. When the form is invalid I'd like it to jump to the comment form's html anchor at the bottom of the page. Right now it goes to the top of the page and you have to scroll down to notice that there's an error.</p>
  
  <p>I tried a couple things that didn't work. Please help!</p>