python - PyCharm wrong working directory at runtime -
i'm writing simple flask application, using form upload image, since upload worked couldn't find image in folder supposed be... printed os.getcwd()
, finding out c:\program files (x86)\jetbrains\pycharm 3.0\jre\jre\bin
. yet, if issue same command in ide console, right one:
c:\\users\\<username>\\pycharmprojects\\<projectname>'
my 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)
the upload part in 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)
Comments
Post a Comment