Joff
Joff

Reputation: 12177

Django how to get data in post that was sent with get?

I have a CBV that call some model methods (which run some processes on the machine, and connect to other websites to retrieve data)

class Edit(View:
    def get(self, request):
        object = Model.objects.get()
        object.foo()
        return object

    def post(self, request):
        ...how can I get the object here without looking it 
        up and calling the method again

I want to get the object again in the post method, but I do not want to call it again, because I do not want to run the process again. Is there a way I can get this info? It was passed into the template via context

Upvotes: 0

Views: 184

Answers (1)

DurgaDatta
DurgaDatta

Reputation: 4170

It will be an attribute of request (reference).

data = request.POST # python dictionary-like

The view gets the argument in this order: request, positional url argument list, named url arugments as dictionary (doc reference):

def post(self, request, *args, **kwargs):
    post_data = request.post
    get_data = request.GET 
    non_named_url_argument_list = args 
    named_url_argument_dict = kwargs

Upvotes: 1

Related Questions