我有Django视图,它负责在文件被删除后返回响应值修改了。但是它什么也没收到。你知道吗
import pyinotify
from django.http import JsonResponse
def get_all_data(request, *args, **kwargs):
print('Started')
print(os.path.join(BASE_DIR, "statics", "input"))
wm = pyinotify.WatchManager()
notifier = pyinotify.Notifier(wm)
wm.add_watch("statics/input.txt", pyinotify.IN_MODIFY, onChange)
notifier.loop()
def onChange(ev): #this function will be executed when chnage detected
f = open("statics/input.txt", "r")
value = f.read()
print('change detected')
return JsonResponse({'foo': value})
我想要的是,当文件被修改时,在不刷新视图的情况下将该文件中的所有数据获取到Django模板。我使用ajax请求从后端获取数据。我不明白这里出了什么问题。你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐