zoukankan      html  css  js  c++  java
  • 开始Flask项目

    1. 新建Flask项目。
    2. 设置调试模式。
    3. 理解Flask项目主程序。
    4. 使用装饰器,设置路径与函数之间的关系。
    5. 使用Flask中render_template,用不同的路径,返回首页、登录员、注册页。
    6. 用视图函数反转得到URL,url_for(‘login’),完成导航里的链接。
    from flask import Flask,render_template
    import config
    
    app=Flask(__name__)
    app.config.from_object(config)
    
    # 首页
    @app.route('/')
    def index():
        return render_template('index.html')
    
    #登录
    @app.route('/login/')
    def login():
        return render_template('login.html')
    
    #注册
    @app.route('/enroll/')
    def enroll():
        return render_template('enroll.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="{{ url_for('static',filename='css/index.css') }}">
    
    </head>
    <body>
    
    <img src="http://www.logo71.com/uploads/allimg/130606/8-1306061335461b.jpg" alt="wo" width="50px">
    <a href="{{ url_for('index') }}">首页</a>
    <a href="{{ url_for('login') }}">登录</a>
    <a href="{{ url_for('enroll') }}">注册</a>
    
    
    
    
    </body>
    </html>
  • 相关阅读:
    浅谈数论
    浅谈数论
    bzoj2190 [SDOI2008]仪仗队
    bzoj2190 [SDOI2008]仪仗队
    35.QQ大数据模型
    34.函数指针数组和多线程
    33.函数指针相关问题
    32.分配数组的方式
    31.内存分配四大函数以及栈上分配内存
    30.锯齿数组
  • 原文地址:https://www.cnblogs.com/iamzhuangyuan/p/7778577.html
Copyright © 2011-2022 走看看