I want to build a simple web application based on Flask and Python for displaying and editing text files. I have written the codes, but it still doesn't work. Everyone who can give me solutions is really appreciated.
from flask import Flask, request, render_template
from os import listdir
app = Flask(__name__)
@app.route('/')
def my_form():
return render_template('index.html')
@app.route('/', methods=['GET,POST'])
def my_form_post():
input_days = request.form['text_box']
if request.method == 'POST':
with open('/users/Devie Andriyani/EditFlask/days.txt', 'w') as f:
f.write(str(input_days))
return render_template('index.html', days=input_days)
if __name__ == '__main__':
app.debug = True
app.run()
<!DOCTYPE html>
<head>
<title>Hello</title>
</head>
<body>
<form action="" method="POST">
<input name="text_box">
<input type="submit">
</form>
</body>
</html>
Aucun commentaire:
Enregistrer un commentaire