使用Flask集成bootstrap的方法
1. 下載flask-bootstrap
pip install flask-bootstrap
2. 找到base.html文件
將site-packages\flask_bootstrap\templates文件夾下的bootstrap目錄copy到你的項(xiàng)目\templates目錄下,確保bootstrap目錄下包含base.html文件,因?yàn)槲覀兒竺嬉玫健?/p>
3. 代碼
user.html :
{% extends "bootstrap/base.html" %} {% block title %}Flask{% endblock %} {% block navbar %} <div class="navbar navbar-inverse" role="navigation"> <div class="container"> <div class="navbar-header"> <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> <span class="sr-only">Toggle navigation</span><span class="icon-bar"></span> <span class="icon-bar"></span><span class="icon-bar"></span> </button> <a class="navbar-brand" href="/" rel="external nofollow" rel="external nofollow" >Flask</a> </div> <div class="navbar-collapse collapse"> <ul class="nav navbar-nav"> <li><a href="/" rel="external nofollow" rel="external nofollow" >Home</a></li> </ul> </div> </div> </div> {% endblock %} {% block content %} <div class="container"> <div class="page-header"> <h1>Hello, {{ name }}</h1> </div> </div> {% endblock %}
MyFlask.py :
from flask import Flask, render_template from flask_bootstrap import Bootstrap app = Flask(__name__) bootstrap = Bootstrap(app) @app.route('/user/<name>') def user(name): return render_template('user.html', name=name) if __name__ == '__main__': app.run()
4. 查看結(jié)果
瀏覽器輸入:http://127.0.0.1:5000/user/Brown
結(jié)果:
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Python的Flask站點(diǎn)中集成xhEditor文本編輯器的教程
- Python的Flask框架中集成CKeditor富文本編輯器的教程
- Python 利用flask搭建一個(gè)共享服務(wù)器的步驟
- 如何使用 Flask 做一個(gè)評(píng)論系統(tǒng)
- 如何基于Python和Flask編寫Prometheus監(jiān)控
- Docker構(gòu)建python Flask+ nginx+uwsgi容器
- 手把手教你將Flask應(yīng)用封裝成Docker服務(wù)的實(shí)現(xiàn)
- flask開啟多線程的具體方法
- 如何解決flask修改靜態(tài)資源后緩存文件不能及時(shí)更改問題
- Flask中sqlalchemy模塊的實(shí)例用法
- Python Flask異步發(fā)送郵件實(shí)現(xiàn)方法解析
- python的flask框架難學(xué)嗎
- flask項(xiàng)目集成swagger的方法
相關(guān)文章
Django部署到服務(wù)器后無法獲取到靜態(tài)元素 The requested resource
寫了一個(gè)Django項(xiàng)目,部署到云主機(jī)后,訪問發(fā)現(xiàn)圖片無法訪問,報(bào)錯(cuò)The requested resource was not found on this server,下面給大家介紹Django部署到服務(wù)器后無法獲取到靜態(tài)元素The requested resource was not found on this server(問題及解決方案),需要的朋友可以參考下2024-02-02Python基于域相關(guān)實(shí)現(xiàn)圖像增強(qiáng)的方法教程
當(dāng)在圖像上訓(xùn)練深度神經(jīng)網(wǎng)絡(luò)模型時(shí),通過對(duì)由數(shù)據(jù)增強(qiáng)生成的更多圖像進(jìn)行訓(xùn)練,可以使模型更好地泛化。本文將為大家介紹Python基于域相關(guān)的圖像增強(qiáng)實(shí)現(xiàn)方法,需要的可以了解一下2022-01-01Django框架使用內(nèi)置方法實(shí)現(xiàn)登錄功能詳解
這篇文章主要介紹了Django框架使用內(nèi)置方法實(shí)現(xiàn)登錄功能,結(jié)合實(shí)例形式詳細(xì)分析了Django框架內(nèi)置方法實(shí)現(xiàn)登錄功能的相關(guān)操作技巧與使用注意事項(xiàng),需要的朋友可以參考下2019-06-06pytorch 數(shù)據(jù)預(yù)加載的實(shí)現(xiàn)示例
在PyTorch中,數(shù)據(jù)加載和預(yù)處理是深度學(xué)習(xí)中非常重要的一部分,本文主要介紹了pytorch 數(shù)據(jù)預(yù)加載的實(shí)現(xiàn)示例,具有一定的參考價(jià)值,感興趣的可以了解一下2023-12-12python在線編譯器的簡(jiǎn)單原理及簡(jiǎn)單實(shí)現(xiàn)代碼
這篇文章主要介紹了python在線編譯器的簡(jiǎn)單原理及簡(jiǎn)單實(shí)現(xiàn)代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-02-02