部署应用程序时无法从实例文件夹加载配置文件 [英] Unable to load configuration file from instance folder when deploying app

查看:216
本文介绍了部署应用程序时无法从实例文件夹加载配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为我的应用程序设置了一个新的virtualenv,来清理已安装的软件包。我在应用程序的实例文件夹中有一个 config.py 文件。有两个配置,一个用于实例文件夹中的开发,另一个用于根文件夹中的生产。该应用程序工作在旧的环境,但现在我得到一个错误,它无法找到配置文件。为什么我得到这个错误,我该如何解决它?

 追踪(最近的最后一次调用):
文件application.py,第12行,在< module>
application.config.from_pyfile('config.py')
文件/Users/pavsidhu/Envs/test/lib/python2.7/site-packages/flask/config.py,第128行,在from_pyfile
打开(文件名)作为config_file:
IOError:[Errno 2]无法加载配置文件(没有这样的文件或目录):'/ Users / pavsidhu / Envs / test / var / application-instance / config.py'

我的项目结构如下:

  / Users / pavsidhu / Envs / test / 
lib / python-3.4 / site-packages /
in /
application.py
static /
templates /
instance /
config.py


Flask认为你的应用程序安装在env中,因为你把它和env放在同一个基本目录下。 在文档中详细描述了这种行为。


$ b


已安装模块或软件包:

  $ PREFIX / lib / python2.X / site-packages / myapp 
$ PREFIX / var / myapp-instance

$ PREFIX是Python安装的前缀。

Flask希望实例文件夹位于 var / myapp-instance 当以这种方式安装时。 (结构不完全相同,但它足够类似愚弄Flask的检测功能)。

您不应该将项目结构与virtualenv结构混合在一起。将两者分开:

  my_env / 
lib /
bin /
my_project /
my_app /
__init__.py
static /
templates /
instance /

查看移至聊天的评论讨论以了解更多详情


I set up a new virtualenv for my app, to clean up the installed packages. I have a config.py file in the app's instance folder. There are two configs, one for dev in the 'instance' folder and one for production in the root folder. The app worked in the old env, but now I get an error that it couldn't find the config file. Why am I getting this error and how do I fix it?

Traceback (most recent call last):
  File "application.py", line 12, in <module>
    application.config.from_pyfile('config.py')
  File "/Users/pavsidhu/Envs/test/lib/python2.7/site-packages/flask/config.py", line 128, in from_pyfile
    with open(filename) as config_file:
IOError: [Errno 2] Unable to load configuration file (No such file or directory): '/Users/pavsidhu/Envs/test/var/application-instance/config.py'

My project structure looks like:

/Users/pavsidhu/Envs/test/
    lib/python-3.4/site-packages/
    bin/
    application.py
    static/
    templates/
    instance/
        config.py

解决方案

Flask thinks your app is installed in the env because you put it in the same base directory as the env. This behavior is described in detail in the docs.

Installed module or package:

$PREFIX/lib/python2.X/site-packages/myapp
$PREFIX/var/myapp-instance

$PREFIX is the prefix of your Python installation.

Flask expects the instance folder to be at var/myapp-instance when installed this way. (The structure isn't exactly the same, but it's similar enough to fool Flask's detection function.)

You should not mix your project structure with the virtualenv structure. Separate the two:

my_env/
    lib/
    bin/
my_project/
    my_app/
        __init__.py
        static/
        templates/
    instance/

See the comment discussion moved to chat for further details.

这篇关于部署应用程序时无法从实例文件夹加载配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆