开始Flask项目

  1. 新建Flask项目。
  2. 设置调试模式。
  3. 理解Flask项目主程序。
  4. 使用装饰器,设置路径与函数之间的关系。
  5. 使用Flask中render_template,用不同的路径,返回首页、登录员、注册页。
  6. 用视图函数反转得到URL,{{url_for(‘login’)}},完成导航条里的链接。
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Hello world</title>
    
        <link rel="stylesheet" type="text/css" href="../static/css/base.css">
        <script src ="../static/js/111.js"></script>
        <style type="text/css">
    
        </style>
    
    </head>
    <body id="myBody">
    
    <nav>
        <img id="myOnOff" onclick="mySwitch()" src="https://www.runoob.com/images/pic_bulbon.gif" height="20" width="20px">
        <a href="http://www.gzcc.cn/">听一听</a>
        <input type="text" name="search">
        <button type="submit">看一看</button>
        <a href="http://localhost:63342/different/templates/login.html?_ijt=ojdam924vfmmmujm9gjll2p9b4">登录</a>
        <a href="http://localhost:63342/different/templates/regist.html?_ijt=ojdam924vfmmmujm9gjll2p9b4">注册</a>
    </nav>
    
    
    <div class="area">
    </div>
    
    <div class="tu">
            <div class="img">
                <a href="https://www.baidu.com/">
                    <img src="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1510321586&di=88dc49354568ade830978051a75ca06d&imgtype=jpg&er=1&src=http%3A%2F%2Fimg.pconline.com.cn%2Fimages%2Fupload%2Fupc%2Ftx%2Fitbbs%2F1311%2F01%2Fc36%2F28231388_1383319859194_mthumb.jpg"></a>
                <div class="desc"><a href="http://www.gzcc.cn">南北的路</a></div>
            </div>
            <div class="img">
                <a href="https://www.baidu.com/">
                    <img src="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1510321704&di=4893fe03de689edc33553bf5c65bd66a&imgtype=jpg&er=1&src=http%3A%2F%2Fimg.pconline.com.cn%2Fimages%2Fupload%2Fupc%2Ftx%2Fitbbs%2F1501%2F20%2Fc5%2F2077108_1421712042746_mthumb.jpg"></a>
                <div class="desc"><a href="http://www.gzcc.cn">朝花夕拾</a></div>
            </div>
            <div class="img">
                <a href="https://www.baidu.com/">
                    <img src="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1509727085025&di=2a378aae3e3d28942ce42ec2b5403219&imgtype=0&src=http%3A%2F%2Fy1.ifengimg.com%2F076e97f56f074d8f%2F2014%2F0310%2Frdn_531d1b50234b3.jpg"></a>
                <div class="desc"><a href="http://www.gzcc.cn">时光背影</a></div>
            </div>
            <div class="img">
                <a href="https://www.baidu.com/">
                    <img src="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1509727202619&di=dd6919b251f8559e42a718001b728e1f&imgtype=0&src=http%3A%2F%2Fupload.news.cecb2b.com%2F2014%2F0227%2F1393489298647.jpg"></a>
                <div class="desc"><a href="http://www.gzcc.cn">风花雪月</a></div>
            </div>
        </div>
    
        <p class="text1">by:厚脸皮羊
    
        </p>
    
    </body>
    </html>>
    
    
    from flask import Flask,render_template
    
    app = Flask(__name__)
    
    
    @app.route('/')
    def index():
        return render_template("index.html")
    
    @app.route("/login")
    def login():
        return render_template("login.html")
    
    @app.route("/regiter")
    def regist():
        return render_template("regist.html")
    
    
    if __name__ == '__main__':
        app.run(debug=True)
    
    

     

     

     

     

     

posted @ 2017-11-03 21:59  201506050096谢阳  阅读(155)  评论(0编辑  收藏  举报