Hi I'm trying to add a new key value pair but I'm receiving an error of TypeError: 'ImmutableMultiDict' objects are immutable the variable I'm trying to add a new key came from a request.form but I can't add a new key value. Any idea on how to achieve this?
Here is my code on my controller
@benefits_api.route("/templates", methods=["POST"])
def store():
parameters = request.form
response = BenefitTemplateService.create(parameters)
return jsonify(response), response['code']
and my service is like this
class BenefitTemplateService(object):
@staticmethod
def create(params):
# some validation here
params['credit_behavior'] = "none"
return params
But I'm getting an error on the assignment for credit_behavior below is the error message
You can use the builtin to_dict()
method of ImmutableMultiDict
, this will provide you with a dict you can freely modify.
You could for example make the following change to your code:
@benefits_api.route("/templates", methods=["POST"])
def store():
parameters = request.form.to_dict()
response = BenefitTemplateService.create(parameters)
return jsonify(response), response['code']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With