I have a flask application which is utilizing Fabric to deploy code to certain machines.
One particular method, fabric.contrib.files.upload_template , requires a filename which is the path of a file I would like to upload to my remote machines.
I have a file, index.php, which I want to place on my remote machines. I want to use upload_template to accomplish this task.
Please note that:
/home/Sparrowcide/flaskapp/path/to/file
won't work. /tmp/path/to/file
, but I'd rather not as this is not a very elegant solution. Well the short answer is that you can pretty much put it wherever you want, I don't think flask will enforce any sort of structure on you here. However I personally would create a subdirectory called data
and then in the flask app I might do something like this:
path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data', 'index.php')
Or, if I felt I was likely to re-use this information (eg if i had multiple files to upload), I might break it out into multiple variables:
SRCDIR = os.path.dirname(os.path.abspath(__file__))
DATADIR = os.path.join(SRCDIR, 'data')
whatever_upload_function(os.path.join(DATADIR, 'index.php'))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.