title: How to pass user id into django ajax post?
body: <p>I am trying ajaxify a like button that works fine without ajax. So I defined a static file:</p>
  
  <pre><code>$(function(){
  
  $('#like').click(function(){
        $.ajax({
                 type: "POST",
                 url: "/news/like/",
                 data: {
                 'post_id': $(this).attr('name'), 
                 'user': '{{request.user.id}}',
                 'csrfmiddlewaretoken': '{{csrf_token}}'
                 },
                 dataType: "json",
                 success: function(response) {
                        alert('You liked this')
                  },
                  error: function(rs, e) {
                         alert(rs.responseText);
                  }
            }); 
      })
  
  });
  </code></pre>
  
  <p>and modified the corresponding view as follows:</p>
  
  <pre><code> @csrf_exempt
  def like(request):
      args = {}
      if request.method == 'POST':
          #lu = User.objects.get(id= request.user.id)
          puid = int(request.POST.get('puid', None))
          lu= User.objects.get(id= puid)
          post_id = request.POST.get('post_id', None)
          try:
              liked_news = News.objects.get(id = post_id)
          except:
              liked_news = None  
  
          if NewsLike.objects.filter(liker=lu.id, news=post_id):
  
              liked_news.likes -=1
              liked_news.save()
              NewsLike.objects.filter(news=post_id, liker=lu.id).delete()
              return HttpResponse(simplejson.dumps(args),
                                  mimetype='application/javascript')            
              #return HttpResponseRedirect(reverse("news.views.post_withslug", args=[liked_news.slug]))
  
          else:
  
              liked_news.likes +=1
              liked_news.save()
              messages.success(request, "You liked this news") 
              newliker = NewsLike(liker=lu.id, news=post_id)
              newliker.save()
  
  
      args.update(csrf(request))
      #return HttpResponseRedirect(reverse("news.views.post_withslug", args=[liked_news.slug]))
      return HttpResponse(simplejson.dumps(args),
                                      mimetype='application/javascript')
  </code></pre>
  
  <p>'@csrf_exempt' decorator is temporarily added to get rid of csrf errors.</p>
  
  <p>However when I click the button I get from firefox</p>
  
  <pre><code>ValueError at /news/like/
  invalid literal for int() with base 10: '{{request.user.id}}'
  </code></pre>
  
  <p>How should I fix this?</p>