1
我一直在嘗試使用jqxUploadFiles,而不是PHP我需要使用python。使用Python上傳函數
在下面的代碼中;
from flask import request
from flask.ext.uploads import UploadSet, configure_uploads, ALL
def upload_file():
files = UploadSet('files', ALL)
app.config['UPLOADED_FILES_DEST'] = '/uploads'
configure_uploads(app, files)
filename = files.save(request.files['files'])
return filename
其中app = Flask(__name__)
,但在這個項目有;
main = Blueprint('main', __name__)
在那裏使用像@main.route('/', methods=['GET', 'POST'])
並有一個create_app功能;
def create_app():
app = Flask(__name__)
app.config.from_object(config['development'])
with app.app_context():
db.app = app
db.init_app(app)
db.create_all()
它用在manage.py文件中;
app = create_app()
manager = Manager(app)
def make_shell_context():
return dict(app=app, db=db)
manager.add_command("shell", Shell(make_context=make_shell_context))
@manager.command
def test():
"""Run the unit tests."""
import unittest
tests = unittest.TestLoader().discover('tests')
unittest.TextTestRunner(verbosity=2).run(tests)
if __name__ == '__main__':
manager.run()
所以我需要使用的功能,如「upload_file()」,但我不明白「應用」,由「create_app()」和藍圖(創建)如何與對方和我如何使用它在upload_file()中。
謝謝你的回答,但它似乎有一件事,我必須檢查小部件內,類似的代碼與一個簡單的HTML工作,但與小部件,我不斷收到錯誤的請求錯誤。 – Berk