File write access on ubuntu server File write access on ubuntu server flask flask

File write access on ubuntu server


You will have to make sure that python process user (in this case Flask application server) has write access to directory where you want to save you file. For example, if you would like to save file into the /var/www directory, make sure that the python process user has the correct access rights.

ls -al /var/wwwsudo chown flask-user /var/www

Also, inside of the Flask route you should probably point to your save directory location instead of saving file into the process working directory (that's what's happening in your case). Something like this will work fine:

@app.route('/save')def save():    with open("/var/www/hello.txt", 'w') as file:        file.write("hello")        file.close()    return "done"

Note: You should probably pick some other directory but /var/www for the place where you store your files.