我正在Linux下开发一个烧瓶应用程序,当我对模板文件进行任何更改时,我很痛苦。
实际上,我已经将我的应用配置为使用
重新加载模板更改TEMPLATES_AUTO_RELOAD = True
PS :当我在Windows模板下开发时,正常重新加载。
编辑
我正在使用内置服务器,我运行我的应用程序:
app = create_app()
manager = Manager(app)
@manager.command
def run():
"""Run in local machine."""
app.run(threaded=True)
这是我的配置类
class DefaultConfig(object):
# Project name
PROJECT = "***"
# Turns on debugging features in Flask
DEBUG = True
# secret key
SECRET_KEY = "**************"
# Configuration for the Flask-Bcrypt extension
BCRYPT_LEVEL = 12
# Application root directory
APP_ROOT = os.path.dirname(os.path.abspath(__file__))
# Application email
MAIL_FROM_EMAIL = "**********"
# Upload directory
UPLOAD_DIR = "static/uploads/"
# Avater upload directory
UPLOAD_AVATAR_DIR = os.path.join(UPLOAD_DIR, 'avatars/')
ALLOWED_AVATAR_EXTENSIONS = set(['png', 'jpg', 'jpeg', 'gif'])
# Instance folder path
INSTANCE_FOLDER_PATH = os.path.join('/home/karim/OpenXC/Dashboard/Flask', 'instance')
# Cache configuration
CACHE_TYPE = 'null'
CACHE_DEFAULT_TIMEOUT = 60
TEMPLATES_AUTO_RELOAD = True
# ToolbarExtention Configuration
DEBUG_TB_ENABLED = False
DEBUG_TB_INTERCEPT_REDIRECTS = False
DEBUG_TB_TEMPLATE_EDITOR_ENABLED = True
DEBUG_TB_PROFILER_ENABLED = True
关于缓存我正在使用缓存扩展,因为它被禁用。请检查配置文件。
谢谢,
答案 0 :(得分:2)
我设法通过将我的模板文件夹添加到Flask app的extra_files参数
来解决我的问题以下是:
extra_dirs = [
'/home/karim/flak_app/templates',
]
extra_files = extra_dirs[:]
for extra_dir in extra_dirs:
for dirname, dirs, files in os.walk(extra_dir):
for filename in files:
filename = os.path.join(dirname, filename)
if os.path.isfile(filename):
extra_files.append(filename)
app.run(threaded=True, extra_files=extra_files)
希望有一天这会帮助某人:)