Get POST values in Django
<p>I had an ajax submit (<strong>GET</strong> query). But it makes change in my database, so smart people told me I should use <strong>POST</strong> instead with <code>{% csfr_token %}</code>.</p>

<p>GET query:</p>

<pre><code>$(document).on('submit','#follow', function(e){
    var $button = $(this).find('button');
    e.preventDefault();
    $.ajax({
        url:'/event/{{ event.id }}/',
        data: "add={{ event.id }}",
        success:function(){
             $('#follow').hide();
             $('#unfollow').show();
        }
    })
});
</code></pre>

<p><strong>views.py</strong></p>

<pre><code>...
event = get_object_or_404(Event, id=event_id)
user = request.user
    if request.GET.get('add'):
        event.users.add(user)
        event.save()
    if request.GET.get('remove'):
        event.users.remove(user)
        event.save()
...
</code></pre>

<p>So I added <code>type:"post",</code> and <code>csrfmiddlewaretoken:$('input[name=csrfmiddlewaretoken])</code> to data but I don't know what to use instead of <code>if request.GET.get('add'):</code> and <code>if request.GET.get('add'):</code>. I tried <code>if request.POST.get('add'):</code> but it doesn't work. So how to use that <code>if</code> with POST values?</p>

<p><strong>UPD.</strong></p>

<p>Ok, what i have now...
<strong>template:</strong></p>

<pre><code>&lt;form id="unfollow" {% if user not in event.users.all %}style="display:none;"{% endif %}&gt;
    &lt;input type="hidden" value="{{ event.id }}" name="remove"&gt;
    &lt;button type="submit" class="btn btn-warning btn-block"&gt;{% trans "Unfollow"%}&lt;/button&gt;
&lt;/form&gt;
</code></pre>

<p>...</p>

<pre><code>$(document).on('submit','#unfollow', function(e){
    var $button = $(this).find('button');
    e.preventDefault();
    $.ajax({
        type:"post",
        url:'/event/{{ event.id }}/',
        data: {
            'action': 'remove'
        },
        success:function(){
            $('#unfollow').hide();
            $('#follow').show();
        }
    })
});
</code></pre>

<p>views.py:</p>

<pre><code>def show_event(request, event_id):
    event = get_object_or_404(Event, id=event_id)
    user = request.user
    if 'action' in request.POST:
        if 'action' == 'add':
            event.users.add(user)
            event.save()
        elif 'action' == 'remove':
            event.users.remove(user)
            event.save()
    return render(request, 'events/event.html', {'event':event, 'user':user}
</code></pre>

<p>No errors, but it doesn't work. <code>success:function()</code> works fine but there are no changes in database. Any advice?</p>

<p>I also tried <code>if request.POST('action') == 'add':</code> but it didn't help</p>