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

Is it possible to send data via POST? #69

Closed
ghost opened this issue Jan 17, 2020 · 6 comments
Closed

Is it possible to send data via POST? #69

ghost opened this issue Jan 17, 2020 · 6 comments
Labels
enhancement New feature or request

Comments

@ghost
Copy link

ghost commented Jan 17, 2020

Hi there,

thanks for that great app, it works perfect. Unfortunately DataTables.js, when sending request to DRF API endpoint puts a lot of parameters to URL. That really clogs up logs. There is simple solution, to this problem: send parameters via POST request, described here: https://stackoverflow.com/questions/33862482.

Is it possible to achieve that with DRFD, make it work with POST as well as GET?

Thanks!

@morenoh149
Copy link
Contributor

@ghost
Copy link
Author

ghost commented Jan 17, 2020

I just did, the same result as in my app.

Console says Failed to load resource: the server responded with a status of 400 (Bad Request) and pop up with DataTables warning: table id=albums - Ajax error. For more information about this error, please see http://datatables.net/tn/7 gets displayed.
Log is "POST /api/albums/?format=datatables HTTP/1.1" 400 15407.

@izimobil
Copy link
Owner

At the moment this is not possible, but it could be easily done by replacing request.query_params with request.POST in DRF-datatables code, a good test would be something like:

if request.POST.get('draw') is not None:
    params = request.POST
else:
    params = request.query_params

If you manage to make it work, feel free to open a PR with tests included.

Thanks.

@izimobil izimobil added the enhancement New feature or request label Jan 18, 2020
@ghost
Copy link
Author

ghost commented Jan 20, 2020

Thanks for that. I tried to make it work but didn't manage. I am getting 403 on my API endpoint after making that change in filters.py:

          # parse query params
          # getter = request.query_params.get
          if request.POST.get("draw") is not None:
              getter = request.POST.get
          else:
              getter = request.query_params.get

I am not sure if problem is that code or my ModelViewSet endpoint.

@CristopherH95
Copy link
Contributor

CristopherH95 commented Apr 9, 2020

Is there any update regarding the possibility of integrating pull request #70, which seems to be related to this? I had planned to use this package, but the environment I'm working in has limits on query strings, which makes using GET requests only a challenge.

izimobil added a commit that referenced this issue Apr 10, 2020
Now DRF-Datatables can handle requests via POST, as explained here:
https://datatables.net/examples/server_side/post.html
@izimobil
Copy link
Owner

Fixed !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants