Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extra docs on the POST call #153

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions docs/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,33 @@ Using DataTables via POST method
By default, the Ajax request that DataTables makes to obtain server-side processing data is an HTTP GET request.
However, there are times when you might wish to use POST, DRF-Datatables can handle this, just configure your Datatable as explained in the `related Datatables documentation section <https://datatables.net/examples/server_side/post.html>`_.

**Note:** Depending on your `CSRF Protection settings <https://docs.djangoproject.com/en/5.1/ref/csrf/>`_, Django might require a CSRF token to authorize any `POST` call. You might need to inject that token on the POST call from the client-side.

.. code:: html

<html>
...
<!-- csrf token tag somewhere in your template -->
{% csrf_token %}
</html>
<script>
const token = $('input[name="csrfmiddlewaretoken"]').val();
const extraData = (data) => {
// Add the CSRF token to the data form so it's not blocked by Django
data.csrfmiddlewaretoken = token;
return data;
};
const table = new DataTable({
// ... your table params
ajax: {
url: '/api/url?format=datatables',
method: 'POST',
data: extraData,
},
});
</script>
</html>


Handling Duplicates in Sorting
------------------------------
Expand Down