python - flask中,instance_path参数的存在意义是什么呢?
黄舟
黄舟 2017-04-18 10:33:26
0
1
632

flask的Flask类初始化参数中有一个instance_path,默认为None

在官网上看了相关文档Instance Folders,反复看了几遍还是不太明白其意义何在,看flask相关案例也没有见过使用的。
自己在机器上做了下测试,输出如下:
view函数加一句print current_app.root_path+'\n'+current_app.instance_path,可以得到:

/home/xxx/Documents/flasky/flasky/app
/home/xxx/Documents/flasky/flasky/instance

其跟root_path的区别仅在于最后一个地方由app变成了instance,这参数是0.8版本才加的,意义何在(既然它和root_path基本一样),加了它之后能够实现什么之前所不能实现的东西吗?

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(1)
伊谢尔伦

After reading the document, there is this paragraph, I wonder if it can answer the questioner’s doubts:

The instance folder is designed to not be under version control and be deployment specific. It’s the perfect place to drop things that either change at runtime or configuration files.

My understanding is that similar to the separation of front-end html and css, the instance folder is separated from the default folder to reduce coupling. It is convenient to modify the instance later without affecting the folder. The None mentioned by the question means that the default instance is under the root folder, and the example corresponding to the question is under the flasky directory.
Now the new version can specify a specific location by setting the instance_path parameter, for example, at the same level as the flasky directory.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!