jquery .load with python flask

Gre*_*own 2 html python jquery flask

我试图在我的烧瓶应用程序中使用jquery .load每次用户按下按钮添加div时添加一个div,但是找不到html文件.

有问题的功能.

$(document).ready(function(){
        $("#add").click(function(){
            $("#form").load('/templates/info.html');
        })
});
Run Code Online (Sandbox Code Playgroud)

info.html文件只包含html的短div部分.

index.html代码,我想在表单后加载info.html div.

  <form id="form" action="{{ url_for('get_data') }}" method="post">
        <input type="button" name="add" value="Add" id="add">
        <input type="submit" id="submit" value="To XML">
    </form>
Run Code Online (Sandbox Code Playgroud)

/templates/info.html

 <div id="info">
     <label>name</label>
     <input type="text" name="name">
     <br>
     <label>asfd</label>
     <input type="text" name="asfd">
      <br>
 </div>
Run Code Online (Sandbox Code Playgroud)

我一直收到404错误.

127.0.0.1 - - [04/Mar/2014 19:55:50] "GET /templates/info.html HTTP/1.1" 404 -
Run Code Online (Sandbox Code Playgroud)

我在本地运行烧瓶应用程序,并且/template/info.html是正确的路径.我只是不知道它为什么不加载那个HTML.当我使用jquery函数和.append()并将长html字符串放入append函数时,我能够使它工作,但添加info.html变得更长我只想加载整个文件.

任何帮助都会非常感谢.

sha*_*aan 6

烧瓶应用程序中的视图定义应返回info.html.换句话说,您应该在烧瓶应用程序中有一个路径和方法:

@app.route('/info')
def info(name):
    return render_template('info.html')
Run Code Online (Sandbox Code Playgroud)

现在在你的jquery代码中你可以加载url /info.Flask默认在templates文件夹中查找模板,因此无需在URL中明确提及