Last active
September 8, 2021 12:17
-
-
Save ciscoinfo/bbe6844888f64e3f115394c5400920a1 to your computer and use it in GitHub Desktop.
article Flask (Python) : lire une requête PUT / POST - views.py - put1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
product_data = { | |
"name": "pates", | |
"price": 1.5, | |
} | |
response = requests.put(f"{BASE_URL}add_json", json=product_data) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@app.route("/products/add_json", methods=["PUT"]) | |
def add_json(): | |
# we can get the data with : | |
# print(f"{request.json=}") | |
# print(f"{request.get_json()=}") | |
new_product = product_schema.load(request.json) | |
add_product(new_product) | |
return {"product added": product_schema.dump(new_product)} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment