Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. def read_file():
  2. try:
  3. with open('text.txt') as f:
  4. return f.readlines()
  5. except FileNotFoundError:
  6. return 'Source file missing or corrupted.'
  7.  
  8. def write_file(contents: str):
  9. with open('text.txt', 'a') as f:
  10. f.write(contents)
  11.  
  12. @app.route('/update', methods=['POST'])
  13. def update():
  14. contents = request.form['input']
  15. write_file(contents)
  16. write_file(' - ')
  17. write_file(getdate())
  18. write_file('n')
  19. return redirect('/editor')
  20.  
  21. @app.route('/editor')
  22. def editor():
  23. contents = read_file()
  24. date = getdate()
  25. return render_template('editor.html',
  26. contents = contents,
  27. title='Editor',
  28. date = date)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement