开始Flask项目

Posted 201508030007杨碧茜

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了开始Flask项目相关的知识,希望对你有一定的参考价值。

  1. 新建Flask项目。
  2. 设置调试模式。
  3. 理解Flask项目主程序。
  4. 使用装饰器,设置路径与函数之间的关系。
  5. 使用Flask中render_template,用不同的路径,返回首页、登录员、注册页。
  6. 用视图函数反转得到URL,url_for(‘login’),完成导航里的链接。
from flask import Flask,render_template

app = Flask(__name__)


@app.route(/)
def index():
    return render_template(base.html)

@app.route(/login/)
def login():
    return render_template(login.html)

@app.route(/regist/)
def regist():
    return render_template(regist.html)


if __name__ == __main__:
    app.run(debug=True)
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>首页</title>

    <link rel="stylesheet" type="text/css" href="../static/css/base.css">
    <script src="../static/js/base.js"></script>
</head>

<body id="myBody">

    <nav>
    <img src="http://p1.img.cctvpic.com/photoAlbum/page/performance/img/2013/8/27/1377583188891_732.jpg" width="800px"height="150px"><br>

        <img id="myOnOff" onclick="mySwitch()" src="http://www.runoob.com/images/pic_bulbon.gif" width="25px">

    <a href="http://www.sesamestreetchina.com.cn/">首页</a>
    <input type="text"name="search">
    <button type="submit">搜索</button>
    <a href="{{ url_for(‘login‘) }}">登录</a>
    <a href="{{ url_for(‘regist‘) }}">注册</a>


</nav>

<div class="area">

</div>

<footer>
    <div class="footer_box">
        [email protected]2017 个人版权,版权所有  作者:杨碧茜</div>
    </footer>

</body>
</html>

 

以上是关于开始Flask项目的主要内容,如果未能解决你的问题,请参考以下文章

开始Flask项目

如何通过单击片段内的线性布局从片段类开始新活动?下面是我的代码,但这不起作用

开始Flask项目

开始Flask项目

开始Flask项目

开始Flask项目