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

    1.新建Flask项目。

    2.设置调试模式。

    3.理解Flask项目主程序。

    4.使用装饰器,设置路径与函数之间的关系。

    5.使用Flask中render_template,用不同的路径,返回首页、登录员、注册页。

    6.用视图函数反转得到URL,{{url_for(‘login’)}},完成导航条里的链接。

    index.html

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
    <nav>
        <<a href="{{ url_for('index') }}">首页</a>
        <a href="http://www.gzcc.cn/">下载</a>
        <input type="text" name="search">
        <button type="submit">搜索</button>
        <a href="{{ url_for('login') }}">登录</a>
        <a href="{{ url_for('zhuce') }}">注册</a>
        <a href="http://www.gzcc.cn/">意见反馈</a>
    </nav>
    
    <a href="http://www.gzcc.cn/">广州商学院
          <br>
          <img src="http://www.gzcc.cn/2016/images/banner.png" width="500" height="39" alt="gzcc.cn"/></a>
    
    </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('/zhuce/')
    def zhuce():
        return render_template('zhuce.html')
    
    
    if __name__ == '__main__':
        app.run(debug=True)

     

  • 相关阅读:
    Django Cookie Session和自定义分页
    ORM版学员管理系统3
    ORM版学员管理系统2
    ORM版学员管理系统1
    Django 基础 ORM系统
    Django 基础 模板系统
    Django 基础 视图系统
    property 与 attribute 的区别?
    SQL数据库相关
    观察者模式-猫叫了,老鼠跑了,主人醒了...
  • 原文地址:https://www.cnblogs.com/gdlyzx/p/7780344.html
Copyright © 2011-2022 走看看