Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/348.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在flask\python上加载更新片段_Javascript_Python_Jquery_Html_Flask - Fatal编程技术网

Javascript 在flask\python上加载更新片段

Javascript 在flask\python上加载更新片段,javascript,python,jquery,html,flask,Javascript,Python,Jquery,Html,Flask,我正在尝试在我的flash应用程序中使用jquery.load来更新div,但这不起作用 routes.py @app.route('/index', methods=['GET', 'POST']) @app.route('/', methods=['GET', 'POST']) def red(): return redirect('/index.html') @app.route('/index.html', methods=['GET', 'POST']) def inde

我正在尝试在我的flash应用程序中使用jquery.load来更新div,但这不起作用

routes.py

@app.route('/index', methods=['GET', 'POST'])
@app.route('/', methods=['GET', 'POST'])
def red():  
    return redirect('/index.html')

@app.route('/index.html', methods=['GET', 'POST'])
def index():
    return render_template('index.html', title='Estat')
index.html

 <script>
     function run() {
    $( "#display" ).load( "/index.html #display" );
    }

    setInterval(run, 1000);
    </script>

<div id="display"><h1>word 2</h1></div> 

函数运行(){
$(“#display”).load(“/index.html#display”);
}
设置间隔(运行,1000);
单词2

我希望每次在一个时间间隔内更改模板文件时,div块的内容都会更改。请帮帮我。

好的,你走对了。div应该正确地重新加载,如果不尝试添加body和head标签的话,这对我有一次帮助。现在由您将想要的任何数据返回到该网页。假设要显示时间: 在python中,使用导入日期时间模块:
import datetime
并使其成为具有以下功能的索引函数:

def index():
    return render_template('index.html', title='Estat', time = str(datetime.datetime.now()))
然后将您的div修改为:
{{time}}


现在,您的网页应该返回时间,并且每秒钟刷新一次,该脚本在没有flask+python的情况下运行良好。我认为问题出在索引上。HTMLC如果您能将我的答案标记为已接受,这样我就知道我已成功回答了您的问题。请记住,请尝试将html包装在适当的正文和标题标记中;例如,它应该看起来像`JAVASCRIPT可以用于变量,但不能用于模板文件中的更改。例如,我在记事本中更改时间{{Time}}上的文本并保存它。我没有重新启动服务器,站点需要查看更改,但这没有发生。我认为这是关于使用调试模式关闭缓存模板的问题。是的,我认为您需要重新启动服务器以查看模板更改,否则请使用调试模式