-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev.py
More file actions
26 lines (21 loc) · 780 Bytes
/
dev.py
File metadata and controls
26 lines (21 loc) · 780 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import os
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
from app import app
# Define the directory to watch
template_dir = 'templates'
class TemplateChangeHandler(FileSystemEventHandler):
def on_modified(self, event):
if event.src_path.endswith('.html'):
print("Detected change in HTML template. Reloading server...")
os.system("pkill -f flask") # Kill Flask server
os.system("python app.py &") # Restart Flask server
if __name__ == "__main__":
observer = Observer()
observer.schedule(TemplateChangeHandler(), template_dir, recursive=True)
observer.start()
try:
app.run(debug=True)
except KeyboardInterrupt:
observer.stop()
observer.join()