应用程序和请求实例在烧瓶中

时间:2013-06-24 20:43:51

标签: python flask

我正在尝试这些代码并看到如果我从函数request=request, app=appsave_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')

0 个答案:

没有答案