码迷,mamicode.com
首页 > 其他好文 > 详细

开始Flask项目

时间:2017-11-03 21:59:00      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:word   ret   debug   def   button   doctype   sheet   cli   lan   

  1. 新建Flask项目。
  2. 设置调试模式。
  3. 理解Flask项目主程序。
  4. 使用装饰器,设置路径与函数之间的关系。
  5. 使用Flask中render_template,用不同的路径,返回首页、登录员、注册页。
  6. 用视图函数反转得到URL,{{url_for(‘login’)}},完成导航条里
    from flask import Flask,render_template
    
    ap = Flask(__name__)
    
    
    @ap.route(‘/‘)
    def shouye():
        return render_template(‘shouye.html‘)
    
    
    @ap.route(‘/zhuce‘)
    def zhuce():
        return render_template(‘zhuce.html‘)
    
    @ap.route(‘/denglu‘)
    def denglu():
        return render_template(‘denglu.html‘)
    
    
    
    if __name__ == ‘__main__‘:
        ap.run(debug=‘True‘)

     

    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(‘/zhuce/‘)
    def zhuce():
        return render_template(‘zhuce.html‘)
    
    if __name__ == ‘__main__‘:
        app.run(debug=True)
    
    
    
    index.html
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>首页</title>
    </head>
    <body>
    <a href="http://127.0.0.1:5000/">首页</a>
    <a href="http://127.0.0.1:5000/login/">登录</a>
    <a href="http://127.0.0.1:5000/zhuce/">注册</a>
    
    <h1>首页</h1>
    </body>
    
    </html>
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <link rel="stylesheet" type="text/css" href="../static/css/aa.css">
        <script src="../static/js/aa.js"></script>
    
    
    </head>
    <body>
    <div class="Outbox">
          <div class="box">
              <h2>Welcome to GZCC!</h2>
              <h3>登录页面</h3>
    
            <div class="input_box">
               账号:<input id="umane"type="text"placeholder="请输入账号">
            </div>
            <div class="input_box">
               密码:<input id="upass"type="password"placeholder="请输入密码">
            </div>
              <div id="error_box"><br></div>
              <div class="input_box">
                  <button onclick="myLogin()">登录</button>
                   <button onclick=window.alert("请重新输入")>取消</button></div>
    
              </div>
    </div>
    
    </body>
    </html>
    复制代码
    复制代码
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>界面</title>
        <link rel="stylesheet" type="text/css" href="../static/css/aa.css">
        <script src="../static/js/aa.js"></script>
    </head> <div class="div1"> <div class="div2">注册</div> 
            <div class="div3"> 请输入你的昵称:<input id="username" type="text" placeholder="请输入你的昵称"> </div> 
            <div class="div3"> 设置密码:<input id="userpass" type="text" placeholder="请输入密码"> </div> 
            <div class="div3"> 重复密码:<input id="userpass1" type="text" placeholder="请再次输入密码"> </div> 
            <div id="error_box"><br></div> <div class="div3"> <button onclick="myLogin()">注册</button> 
    </div> 
    </div> 
    <br> 
    </body> 
    </html>

     

开始Flask项目

标签:word   ret   debug   def   button   doctype   sheet   cli   lan   

原文地址:http://www.cnblogs.com/xiepingjian/p/7780395.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!