Добавил возможность редактирования основной страницы

(хотя вряд ли стоит так делать)
This commit is contained in:
Lulzette 2021-09-07 07:29:43 +03:00
parent cca16d69b5
commit 7c67f2f5bd

14
main.py
View File

@ -60,6 +60,20 @@ def index():
except TypeError: except TypeError:
return abort(404, 'No such page') return abort(404, 'No such page')
@route('/', method='POST')
def post():
'''
Insert/Update post
'''
body = request.forms.get('body')
# If post exists, update it
if posts.find_one({'name': '/'}):
newPost = {'$set': {'text': body}}
return str(posts.update_one({'name': '/'}, newPost))
# Else - create new
else:
newPost = {'name': '/', 'text': body}
return str(posts.insert_one(newPost).inserted_id)
if __name__ == '__main__': if __name__ == '__main__':
run(host='0.0.0.0', port=8081, reloader=True, debug=True) run(host='0.0.0.0', port=8081, reloader=True, debug=True)