How to return data in POST request (django/tastypie)

A G

How do I customise and place data in the response to a POST request? At first I thought I should place my code in obj_create but it looks like create_response is the place I should place my code.

My resource looks like this:

class TestResource(ModelResource):
    class Meta:
        queryset = Test.objects.all()
        always_return_data = True
        authentication = Authentication()
        authorization = Authorization()

    def create_response(self, request, data, response_class=HttpResponse, **response_kwargs):
        super(TestResource, self).create_response(request, data, response_class, **response_kwargs)

However I get a HTTP/1.0 204 NO CONTENT error; when I remove the create_response function, it works as normal. Shouldn't calling super on the function I'm overriding have no effect?

Bartosz Dabrowski

You must return response.

def create_response(self, request, data, response_class=HttpResponse, **response_kwargs):
    return super(TestResource, self).create_response(request, data, response_class, **response_kwargs) 

But I would use dehydrate method for that:

class TestResource(ModelResource):
    class Meta:
        queryset = Test.objects.all()
        always_return_data = True
        authentication = Authentication()
        authorization = Authorization()

    def dehydrate(self, bundle):
        if bundle.request.method == 'POST':
            bundle.data['my_custom_data'] = 'my_data'

        return bundle

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to return data in POST request (django/tastypie)

From Dev

How to structure httr POST request to return site data?

From Dev

Use Post Request to retrieve data and return a List

From Dev

How to configure Spring Data REST to return the representation of the resource created for a POST request?

From Dev

Swift - Return data from NSURLSession when sending POST request

From Dev

AngularJS Post Request not catching JSON data return from PHP

From Dev

How to access data sent in post request?

From Dev

how to print the data from post request on console

From Dev

how much of data usage a http post request?

From Dev

How to serialize request.POST data?

From Dev

How to send data in a post request with RestClient

From Dev

how much of data usage a http post request?

From Dev

How to post data as json from request payload?

From Dev

How to get post request data using slim?

From Dev

How to get data from POST request

From Dev

How to formulate data object for POST request in AJAX

From Dev

how does $.post know what data to return?

From Dev

How to POST binary data in request using request library?

From Dev

How do I return strings from an asynchronous POST request?

From Dev

RESTful POST request, If the record already exists on POST data, do we return 200 OK or 304 Not Modified?

From Java

How can I post data as form data instead of a request payload?

From Dev

POST request: return status reports

From Dev

Django post request data

From Dev

No data in params on POST request

From Dev

POST request with form data

From Dev

How to POST xml data through RestTemplate in the body of request?

From Dev

How to get POST data from request asp mvc 5

From Dev

how to make a fake post request using unittest module with cookies and data?

From Dev

How to add data to a form when submitting via a POST AJAX request?

Related Related

  1. 1

    How to return data in POST request (django/tastypie)

  2. 2

    How to structure httr POST request to return site data?

  3. 3

    Use Post Request to retrieve data and return a List

  4. 4

    How to configure Spring Data REST to return the representation of the resource created for a POST request?

  5. 5

    Swift - Return data from NSURLSession when sending POST request

  6. 6

    AngularJS Post Request not catching JSON data return from PHP

  7. 7

    How to access data sent in post request?

  8. 8

    how to print the data from post request on console

  9. 9

    how much of data usage a http post request?

  10. 10

    How to serialize request.POST data?

  11. 11

    How to send data in a post request with RestClient

  12. 12

    how much of data usage a http post request?

  13. 13

    How to post data as json from request payload?

  14. 14

    How to get post request data using slim?

  15. 15

    How to get data from POST request

  16. 16

    How to formulate data object for POST request in AJAX

  17. 17

    how does $.post know what data to return?

  18. 18

    How to POST binary data in request using request library?

  19. 19

    How do I return strings from an asynchronous POST request?

  20. 20

    RESTful POST request, If the record already exists on POST data, do we return 200 OK or 304 Not Modified?

  21. 21

    How can I post data as form data instead of a request payload?

  22. 22

    POST request: return status reports

  23. 23

    Django post request data

  24. 24

    No data in params on POST request

  25. 25

    POST request with form data

  26. 26

    How to POST xml data through RestTemplate in the body of request?

  27. 27

    How to get POST data from request asp mvc 5

  28. 28

    how to make a fake post request using unittest module with cookies and data?

  29. 29

    How to add data to a form when submitting via a POST AJAX request?

HotTag

Archive