Commit b7e9bae6 authored by fangzhipeng's avatar fangzhipeng

添加环境配置

parent 0d82859f
from flask import Flask
from weather.service import weather
import socket
from config import config
app = Flask(__name__)
......@@ -25,8 +25,7 @@ app.wsgi_app = PrefixMiddleware(app.wsgi_app, prefix='/api')
app.register_blueprint(weather)
if __name__ == '__main__':
hostname = socket.gethostname()
if (hostname == 'VM-151-99-ubuntu'):
if (not config.isDebug):
app.run(port=9999)
else:
app.run(debug=True)
\ No newline at end of file
import socket
hostname = socket.gethostname()
isDebug = False
if (hostname == 'VM-151-99-ubuntu'):
from config.env import production as envconfig
isDebug = False
else:
from config.env import local as envconfig
isDebug = True
def get_config(config_name):
"""
返回对应的配置文件属性
:param config_name:
:return:
"""
return getattr(envconfig, config_name)
\ No newline at end of file
#mysql地址
mysql_url='mysql+pymysql://root:root@localhost/daylife?charset=utf8mb4'
\ No newline at end of file
......@@ -3,9 +3,9 @@ from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, String
from sqlalchemy.orm import sessionmaker
from config import config
engine = create_engine("mysql+pymysql://root:root@localhost/daylife?charset=utf8mb4", echo=True)
engine = create_engine(config.get_config('mysql_url'), echo=True)
# 创建DBSession类型:
DBSession = sessionmaker(bind=engine)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment