标签:主程 deb login _for return ati color 搜索 personal
1.新建Flask项目。
2.设置调试模式。
3.理解Flask项目主程序。
4.使用装饰器,设置路径与函数之间的关系。
5.使用Flask中render_template,用不同的路径,返回首页、登录员、注册页。
6.用视图函数反转得到URL,{{url_for(‘login’)}},完成导航条里的链接。
from flask import Flask from flask import render_template app = Flask(__name__) @app.route(‘/login‘) def login(): return render_template(‘login.html‘) @app.route(‘/register‘) def register(): return render_template(‘register.html‘) @app.route(‘/‘) def index(): return render_template(‘index.html‘) if __name__ == ‘__main__‘: app.run(debug=True)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>首页</title> </head> <body> <a href="{{ url_for(‘index‘) }}">首页</a> <a href="{{ url_for(‘login‘) }}">login</a> <a href="{{ url_for(‘register‘) }}">register</a> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>My Personal Website-注册.</title> <link href="../static/css/register.css" rel="stylesheet" type="text/css"> <script type="text/javascript" src="../static/js/register.js"></script> <link href="../static/css/base.css" rel="stylesheet" type="text/css"> <script type="text/javascript" src="../static/js/base.js"></script> </head> <body> <nav class="body"> <div> <img id="imgs" src="../static/images/heben.jpeg"> <a class="s" href="">首页</a> <a class="s" href="">下载APP</a> <input id="sousuo" type="text" name="search" placeholder="请输入搜索内容:"> <button id="sou" type="submit">搜索</button> <a class="login" href="login.html">登录</a> <a class="register" href="register.html">注册</a> <img id="myOn_Off" onclick="mySwitch()" src="../static/images/taiyang.png" width="50" height="50"> </div> </nav> <footer> <div class="footer_box"> Copyright@2017-2027 个人版权,版权所有 作者:JZX telephone:0000-1234567 mobile phone:11111111111 </div> </footer> <div class="box"> <div> <a href="login.html">登录</a> <a style="color: antiquewhite">*</a> <a href="register.html">注册</a> </div> <br> <div class="name" align="center"> <input id="uname" type="text" placeholder="登录账号:"> </div> <br> <div class="telephone" align="center"> <input type="tel" id="uuser" placeholder="请输入你的手机号:"> </div> <br> <div class="email" align="center"> <input type="password" id="upass" placeholder="设置你的密码:"> </div> <br> <div class="email" align="center"> <input type="password" id="upass2" placeholder="请输入你的密码:"> </div> <br> <div> <div id="error_box"></div> <div> <button id="register" onclick="myRegister()">注册</button> </div> <a class="login-register" href="login.html">进入登录界面</a> <div id="footer" style="background-color: transparent;clear:both;text-align:center;">版权 . duym@jzx</div> </div> </div> </body> </html>
标签:主程 deb login _for return ati color 搜索 personal
原文地址:http://www.cnblogs.com/jzx-089/p/7780377.html