Я пытаюсь создать сервер Bottle, который позволяет пользователю сохранять файл на сервере (я знаю, что это имеет большую дыру в безопасности, добавляя систему аутентификации позже).Когда я пытаюсь сохранить файл с помощью веб-страницы, я получаю эту ошибку.[Errno 2] No such file or directory: '/storage/test.txt'
main.py
from bottle import *
class File():
def __init__(self, Path):
self.Path = Path
def read(self):
self.File = open(self.Path, 'r')
return [self.File.read(), self.File.close()][0]
@route('/')
def Request():
return File('responses/index.html').read()
@route('/actions/save')
def Request():
return File('responses/actions/save/index.html').read()
@route('/actions/save', method='POST')
def Request():
Source = request.forms.get('source')
Path = request.forms.get('path')
try:
FileObj = open('/storage/{}'.format(Path), 'w')
FileObj.write(Source)
FileObj.close()
return File('responses/actions/save/ok.html').read()
except Exception as Message:
return File('responses/actions/save/error.html').read().format(Message=Message)
if __name__ == '__main__':
run(host='0.0.0.0', port=8000)
ответы / действия / сохранить / index.html
<html>
<head>
<link rel="stylesheet" href="/style/index.css">
<title>Save File</title>
</head>
<body>
<h1>Save File</h1>
<form action="/actions/save" method="post">
<textarea name="source" cols="40" rows="10"></textarea><br>
Path: <input type="text" name="path" value="/public"><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
index.html
<html>
<head>
<link rel="stylesheet" href="/style/index.css">
<title>POSTRun</title>
</head>
<body>
<h1>PostRun</h1>
<a href='/actions/save'>Save File</a>
</body>
</html>