I'm working on a python project and I want to write some data in a file text.txt but I have this error : UnboundLocalError: local variable 'data' referenced before assignment
This is my code :
from flask import Flask, request, jsonify
app = Flask(__name__)
@app.route('/', methods=['POST','GET'])
def createapp():
if request.method == 'POST':
data = request.json
print(data)
with open('text.txt', 'a') as file:
file.write(data)
if __name__ =='__main__':
app.run()