0

Is there any special instruction when I am writing a file in a flask environment? I first got "permission denied" error, and then I run the pycharm as administrator, and no error returned, but my file didn't get written(nothing happened!).

@app.route('/')
def index():
    with open('test.txt', "wb") as test:
        test.write("I wrote in test!")
    return render_template('index.html')

I am doing a project that write a music midi file, store in the project directory, then play the midi on the webpage later to the user. But there seems no way that I can create a file in flask.

Natalia
  • 153
  • 1
  • 8

1 Answers1

0

you are trying to write a text file not a binary file.

Try,

with open('test.txt', "w") as test:
        test.write("I wrote in test!")
Pyd
  • 6,017
  • 18
  • 52
  • 109