zoukankan      html  css  js  c++  java
  • 蓝图

    #coding=utf-8
    
    from flask import Blueprint, request, render_template, redirect, url_for, flash
    #创建一个蓝图 传入参数分别是蓝图名称,蓝图所在目录,必选, 其余为可选,如果静态文件所在目录
    book_bp = Blueprint("book", __name__, template_folder="../templates")
    books = ["The lord of the ring", "Head first html and css", "The Next"]
    
    @book_bp.route("/", methods=["GET"])
    def index():
        return "Hello, Welcome to my book library"
    
    
    @book_bp.route("/book", methods=["GET", "POST"])
    def handle_book():
        if request.method == "POST":
            title = request.form.get("title")
            if title:
                books.append(title)
                flash("Add book succussfully.")
                return redirect(url_for("book.handle_book"))
        return render_template("book.html", books=books)
    
    @book_bp.route("/book/<name>")
    def get_book_info(name):
        book = [name]
        if not name in books:
            book = []
        return render_template("book.html", books=book)
    
    
    #coding=utf-8
    #注册蓝图
    from flask import Flask
    from flask import render_template
    from book.book import book_bp
    
    
    app = Flask(__name__)
    app.secret_key = "YouWillNeverGuessWhatIThink"
    
    app.register_blueprint(book_bp)
    
    @app.route("/home")
    def hello_world():
        return "hello world"
    
    
    @app.errorhandler(404)
    def page_not_found(error):
        return render_template("404.html")
    
    
    
    
    if __name__ == '__main__':
        app.run(debug=True)
  • 相关阅读:
    十四、内部类
    十三、模板设计模式
    十二、面向对象之多态
    三、泛型
    Spring Security学习笔记
    Maven构建web项目在Eclipse中部署的几种方法
    spring如何实现定时任务
    安装jar包到本地仓库
    使用java对pdf转成tiff文件
    word文档转pdf解决修订问题
  • 原文地址:https://www.cnblogs.com/themost/p/9271854.html
Copyright © 2011-2022 走看看