我正在尝试这些代码,看看如果我request=request, app=app
从函数中删除默认参数 () save_files
,save_file
然后代码不能按预期工作(python 解释器没有进入函数 save_file)。为什么?
def save_files(request=request, app=app):
"Save all files in a request to the app's upload folder."
for _, filestorage in request.files.iteritems():
# Workaround: larger uploads cause a dummy file named '<fdopen>'.
# See the Flask mailing list for more information.
if filestorage.filename not in (None, 'fdopen', '<fdopen>'):
save_file(filestorage, app=app)
def save_file(filestorage, app=app):
"Save a Werkzeug file storage object to the upload folder."
filename = secure_filename(filestorage.filename)
filepath = os.path.join(app.config['PICTURE_FOLDER'], filename)
filestorage.save(filepath)
@app.route('/_add_picture', methods=['GET', 'POST'])
def add_picture():
if request.method == 'POST':
save_files()
return 'Uploaded'
if request.method == 'GET':
return render_template('add_picture.html')