1. 下载flask-bootstrap
1
|
pip install flask - bootstrap
|
2. 找到base.html文件
将site-packages\flask_bootstrap\templates文件夹下的bootstrap目录copy到你的项目\templates目录下,确保bootstrap目录下包含base.html文件,因为我们后面要用到。
3. 代码
user.html :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
{% 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 :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
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. 查看结果
浏览器输入:http://127.0.0.1:5000/user/Brown
结果:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/qq_16912257/article/details/54412358