我正在使用flask
作为框架构建一个小型的Restful api。我正在使用Pycharm作为我的IDE。我正在定义一个应用程序工厂,该工厂指向我的实例目录中的一个配置文件。我的问题是Pycharm忽略了配置文件,并使用默认的ENV values
运行Flask服务器。如何告诉Pycharm使用配置文件中定义的ENV
值。
我创建了一个新的运行/调试配置,请确保脚本路径正确,我取消选择所有默认配置
# my app factory /todo_api/__init__.py
from flask import Flask, render_template
from . import models
def create_app(test_config=None):
app = Flask(__name__, instance_relative_config=True)
app.config.from_pyfile('dev_config.py')
@app.route('/hello')
def hello_world():
return 'Hello World'
@app.route('/')
def my_todos():
return render_template('index.html')
return app
#my config at /instance/dev_config.py
HOST = '0.0.0.0'
PORT = 8000
SECRET_KEY = 'GWK~M$F2"|[|i|,KEJWxvA5~JQN!}fUz>|&h`>g.K2/p)%t3%4P:tuR6G6A'
DEFAULT_RATE = "100/hour"
# at server initialization on local machine I expect to see:
* Serving Flask app "todo_api/__init__.py:create_app"
* Environment: development
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: on
* Running on http://127.0.0.0:8000/ (Press CTRL+C to quit)
# actual results
* Serving Flask app "todo_api/__init__.py:create_app"
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)