I am developing a flask application under Linux, and i’m suffering when i make any changes to template files.
Actually i well configured my app to reload on template changes using
TEMPLATES_AUTO_RELOAD = True
PS: when i develop under Windows templates are reloading normally.
EDIT
I am using the built in server, and i run my app like this :
app = create_app() manager = Manager(app) @manager.command def run(): """Run in local machine.""" app.run(threaded=True)
Here is my configuration class
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
About cache i am using the cache extension by it’s disabled. Please check the config file.
Thanks,
Advertisement
Answer
I managed to fix my issue by adding my template folder to extra_files parameter of Flask app
Here is how :
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)
Hope this will help someone someday 🙂