title: How to display and edit text files on the web page using python and Flask?
body: <p>I want to build a simple web application based on Flask and Python for displaying and editing a text file in my directory path that I have created before on the web page. I have written the codes and can be run, but the results are not as expected. Everyone who can give me solutions is really appreciated.</p>
  <pre><code>from flask import Flask, request, render_template, redirect, url_for
  from pathlib import Path
  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():
      path=Path('/users/Devie Andriyani/EditFlask/days.txt') # set the path to your file here
      if not path.exists():path.touch()
      input_days = request.form['text_box']
      if request.method == 'POST':
     with open('/users/Devie Andriyani/EditFlask/days.txt', 'w') as f:
          f.write(request.form.get('text_box',None))
     return redirect(url_for('my_form_post'))
  
  if __name__ == '__main__':
      app.debug = True
      app.run()
  </code></pre>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
     &lt;head&gt;
        &lt;title&gt;Hello&lt;/title&gt;
     &lt;/head&gt;
  
     &lt;body&gt;
        &lt;form action="" method="POST"&gt;
          &lt;input name="text_box" value={{days}}&gt;
          &lt;input type="submit"&gt;
        &lt;/form&gt;
     &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>
  <p><a href="https://i.stack.imgur.com/vydku.png" rel="nofollow noreferrer">And here's the result. I don't get the result as I expected. It should edit a text file </a></p>