Forums

[FLASK] it's my program or pythonanywhere the problem

I am writing a Flask code on pythonanywhere and I don't no if it's my program or pythonanywhere the problem. The problem is that the file "db_game.txt" is empty. Here is my code: flask_app.py:

import flask

app = flask.Flask(name)

@app.route('/', methods=['POST'])

def server(): data = flask.request.get_json()

with open("db_game.txt", "a") as f:
    f.write(str(data))
print("data:",data)
return  data

requests.py:

import requests import json

URL = "http://me.pythonanywhere.com"

d = json.dumps({"one": "two"}) response = requests.post(URL, json=d) print(response.text)

db_game.txt:

Make sure you're actually writing to the file that you think you're writing to: https://help.pythonanywhere.com/pages/NoSuchFileOrDirectory/

I'm sure that didn't work but I find a way to do what I wan't.

Thanks for letting us know!