title: Django csrf token when posting multiple forms
body: <p>I am trying to create a page that includes multiple forms, and I want to build something like a "like button" so that I can "like" some posts in a page. I also want to put some restriction so that I can like every post, but can only like each post once</p>
  
  <p>Now I encounter a problem that I can only "like" a post. When I click another "like" to another post, csrf error would occur(CSRF verification failed. Request aborted.). I want to know how to like multiple posts in a page at the same time. </p>
  
  <p>Does it have something to do with how and where to put {% csrf_token %}? This article(<a href="https://stackoverflow.com/questions/17537562/how-will-the-inclusion-of-two-forms-affect-my-csrf-token-use">How Will the Inclusion of Two Forms Affect my CSRF Token Use?</a>) says I should put {% csrf_token %} in every form, but it doesn't seem to work.</p>
  
  <p>Here's my code:  </p>
  
  <p><strong>models.py</strong></p>
  
  <pre><code>class Restaurant(models.Model):
      name = models.CharField(max_length=20)
      phone_number = models.CharField(max_length=15)
      address = models.CharField(max_length=50, blank=True)
      likes = models.DecimalField(max_digits=2,decimal_places=0, default=0)
  </code></pre>
  
  <p><strong>views.py</strong></p>
  
  <pre><code>&lt;!doctype html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;title&gt; Menu &lt;/title&gt;
      &lt;meta charset='utf-8'&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;h2&gt;餐廳列表&lt;/h2&gt;
  
      &lt;table&gt;
          &lt;tr&gt;
              &lt;th&gt;ID&lt;/th&gt;
              &lt;th&gt;NAME&lt;/th&gt;
              &lt;th&gt;PHONE&lt;/th&gt;
              &lt;th&gt;ADDRESS&lt;/th&gt;
              &lt;th&gt;LIKES&lt;/th&gt;
              &lt;th&gt;LIKE IT!&lt;/th&gt;
          &lt;/tr&gt;
          {% for r in restaurants %}
              &lt;tr&gt;
                  &lt;td&gt; {{ r.id }} &lt;/td&gt;
                  &lt;td&gt; {{ r.name }} &lt;/td&gt;
                  &lt;td&gt; {{ r.phone_number }} &lt;/td&gt;
                  &lt;td&gt; {{ r.address }} &lt;/td&gt;
                  &lt;td&gt; {{ r.likes }} &lt;/td&gt;
                  &lt;td&gt;
                  &lt;form id={{ r.id }} action="" method="post"&gt;
                      {% csrf_token %}
                      &lt;input type="hidden" name="ok" value="yes"&gt;
                      &lt;input class="submit" type="submit" value="Upvote"&gt;
                  &lt;/form&gt;
                  &lt;/td&gt;
  
              &lt;/tr&gt;
          {% endfor %}
      &lt;/table&gt;
  
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>views.py</strong></p>
  
  <pre><code>def list_restaurants(request):
      restaurants = Restaurant.objects.all()
  
      if request.method == "POST":
          post = Restaurant.objects.get(id=request.POST['id'])
          post.likes += 1
          post.save()
          return render_to_response('restaurants_list.html',locals())
      else:
          return render(request, 'restaurants_list.html',locals())
  </code></pre>