Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/371.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/jquery/69.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的jquery导航栏_Javascript_Jquery_Python_Html_Flask - Fatal编程技术网

Javascript 带有flask/python的jquery导航栏

Javascript 带有flask/python的jquery导航栏,javascript,jquery,python,html,flask,Javascript,Jquery,Python,Html,Flask,我用Dreamweaver构建了一个简单的网页,包括一个使用jquery的简单导航栏。它正在使用Flask在我的RPi上运行,但导航不再工作 HTML代码: <table width="100%" height ="100%" border="0"> <tr> <td width="120px" valign="top"> <ul id="Navigation" class="nav"> <li

我用Dreamweaver构建了一个简单的网页,包括一个使用jquery的简单导航栏。它正在使用Flask在我的RPi上运行,但导航不再工作

HTML代码:

<table width="100%" height ="100%" border="0">
   <tr>
     <td width="120px" valign="top">
       <ul  id="Navigation" class="nav">
        <li id="home" ><a data-site="home" href=""><br><img src="{{ url_for('static',filename='icons/Home.png')}}" width="40" height="40"><br> Home</a></li>
        <li id="light"><a data-site="light" href=""></a></li>
        <li id="htpc"><a data-site="htpc" href=""></a></li>

      </ul>

     </td>

     <td class="content" valign="top" ></td>
   </tr>
 </table>

jquery:

 <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
    <script type="text/javascript">

        $(document).ready(function(){ 

            $(".content").load("{{ url_for('static', filename='home.html')}}");
            $('.nav a').click(function(e){              
                e.preventDefault();                
                var site = $(this).data('site'); 

                site = site + '.html';                

                $(".content").load(site); 
            });
        });
</script>

$(文档).ready(函数(){
$(“.content”).load(“{url_for('static',filename='home.html')}”);
$('.nav a')。单击(函数(e){
e、 预防默认值();
var site=$(this.data('site');
site=site+'.html';
$(“.content”).load(站点);
});
});
我用函数的
url\u替换了一些链接,该函数工作得很好(用于图像)。我让
home.html
工作,但其余的都不工作。 当我单击li元素“
light
”时,我得到了
404
错误“
light.html未找到”
”。我确信路径是错误的,但如何用简单的方法解决这个问题?

让它工作起来了

*.py文件中需要
@app.route

(...)
@app.route("/light", methods=['GET'])
def light():
    return render_template('light.html')
(...)
light.html
必须位于
/templates
文件夹中。 它可以与
“/light”
一起使用。我也是为
home.html
这样做的。也许不是最好的方法,但它是有效的

像这样:

<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
    <script type="text/javascript">

        $(document).ready(function(){ 

            $(".content").load("/home");
            $('.nav a').click(function(e){              
                e.preventDefault();                
                var site = $(this).data('site'); 

                 site  = '/' + site;                

                $(".content").load(site); 
            });
        });
</script>

$(文档).ready(函数(){
$(“.content”).load(“/home”);
$('.nav a')。单击(函数(e){
e、 预防默认值();
var site=$(this.data('site');
地点='/'+地点;
$(“.content”).load(站点);
});
});