简体   繁体   中英

How to extract data from Django api rest framework POST method

I'm trying to build an API that execute a script with some variables, those variables are in the POST msg, like {'command': 'start', 'name': 'var'}.. The thing is that I can't find the function the extraction those exact values and not all of the data. after a few days I tried with flask but that idea is the same.

from flask import Flask, request
from flask_restful import Api, Resource
import os

script = 'python /home/USER/somepath/client.py start '

app = Flask(__name__)
api = Api(app)



class Netflix(Resource):
    def get(self):
        return "Success", 201
    def post(self):
        name = request.data
        os.system(script+name)
        print(name)
        return "Success", 201


api.add_resource(Netflix, "/netflix")

if __name__ == "__main__":
    app.run(debug=True, host='0.0.0.0', port=8000)
class Netflix(Resource):
    def get(self):
        return "Success", 201
    def post(self):
        command = request.headers.get('command')
        name = request.headers.get('name')
        print(command+' '+name)
        os.system(script+command+' '+name)
        return "Success", 201

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM