Phyton Flask框架学习记录。

 

   注意:在左侧菜单栏(在JQuery插件库下载的)右边是采用<iframe> 标签嵌入其他页面,此时标签的src应用用后台中的方法名称(本人测试用的是无参数的方法),

而页面跳转window.location.href和<a>标签的href的url必须是后台路由名称。

1,首先是在左侧菜单栏中加了一个<a>标签,并且写了个调用后台返回infor.html页面的js方法:

 

<a href="javascript:void(0)" id="btninfor22" onclick="showdata()" style="font-style: initial;background-color: #d6e9c6"> 学生信息表</a>

 

 

 function showdata() {

             $.get("/infor", {"hno": "123"},
                 function (data, status) {
                     if (data != "undefined" && data != "insertok") {
                         //$("#content").html(data);
                         //src里url是后台里的方法名称。而<a>标签里href的地址是后台路由名称
                         $("#content").html('<iframe style="width: 1100px;height: 600px" src="{{ url_for('py_infor')}}" id="myiframe"  frameborder="0"></iframe>');
                     }
                     else {
                         alert("插入失败,状态:" + status);
                     }
                 });
         }

 

2.其次在左侧菜单栏右边放了个<div>:

 

<div class="container" style="background-color: #e6e6e6" id="content">
    <p>右侧内容</p>
</div>

 

3.最后在后台中写好方法(py_infor()):

 

@app.route('/infor') #页面链接该路由名称
def py_infor():
    # //查询数据
    getsql = "SELECT * FROM dbo.infor"
    inforlist = getdata(getsql)
    return render_template('infor.html', inforlist=inforlist)
    return render_template('infor.html')  # send_file('/templates/testhtm.html') #

 2018.7.24  added by longdb

window.open()打开个新页面:url必须是后台方法名称。

            window.open('{{url_for("py_getaddinfor") }}','_blank','width=500px,height=500px,resizable=0,scrollbars=auto');

 

2018.7.25 added by longdb

在一个页面中插入另外一个页面:


<div class="container" style="background-color: #e6e6e6" id="content">
    <p>右侧内容</p>
    {% include "editaddinforview.html" %}
</div>

 


最后效果:

 

posted @ 2018-07-22 15:02  longdb  阅读(1160)  评论(0编辑  收藏  举报