我正在编写一个简单的烧瓶应用程序,使用表单上传图像,但由于上传工作但我无法在文件夹中找到它应该是...我打印os.getcwd()
,发现它是C:\Program Files (x86)\JetBrains\PyCharm 3.0\jre\jre\bin
。
但是,如果我在IDE控制台中发出相同的命令,我会得到正确的命令:
C:\\Users\\<username>\\PycharmProjects\\<projectname>'
我的init.py
db = database.Database()
app = Flask(__name__, static_url_path="/static", static_folder="static")
print(app.static_folder)
#app.debug = True
app.config.from_object('config')
#toolbar = DebugToolbarExtension(app)
#app.config['DEBUG_TB_PROFILER_ENABLED'] = True
lm = LoginManager()
lm.login_view = 'login'
lm.anonymous_user = Anonymous
lm.init_app(app)
我的app.py中的上传部分
if form.validate_on_submit():
item['name'] = form.name.data
item['order'] = form.order.data
item['description'] = form.description.data
item['category'] = form.categories.data
item['tags'] = form.tags.data
if form.image.data:
image_name = mytools.secure_filename(form.image.data.filename)
filepath = os.path.join(folder, image_name)
image_data = Image.open(form.image.data)
image_data.save(filepath.encode('utf-8'))
mytools.resize_photo(filepath)
item['image'] = image_name
db.db.products.save(item)