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)
  • 相关阅读:
    Git的Patch功能
    Android系统进程Zygote启动过程的源代码分析
    Android深入浅出之Zygote
    Android Ams浅析
    Handle机制详解
    详解Android中AsyncTask的使用
    将博客搬至CSDN
    Titanium studio安装
    Titanium studio介绍
    Android WebView useragent
  • 原文地址:https://www.cnblogs.com/themost/p/9271854.html
Copyright © 2011-2022 走看看