如何集成Flask-Bootstrap与我的Flask项目一起使用?

时间:2017-01-03 14:22:20

标签: python twitter-bootstrap-3 flask flask-bootstrap

我已经安装了flask-bootstrap并通过virtualenv导入到我的项目中。我正在尝试启动' base.html' flask-bootstrap包附带的模板,但是当我加载项目时,网站没有显示任何bootstrap的迹象。我该如何解决这个问题? 下面是我导入flask_bootstrap包的方法。

from flask import Flask, render_template
from flask_script import Manager
from flask_bootstrap import Bootstrap

app = Flask(__name__)
manager = Manager(app)
bootstrap = Bootstrap(app)


@app.route('/index')
def index():
    return render_template('index.html')

@app.route('/user/<name>')
def user(name):
    return render_template('user.html', name=name)


if __name__ == '__main__':
    manager.run()

此外,这是我试图启动包的代码:

{% extends "bootstrap/base.html" %}
{% block title %}Flasky{% 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="/">Flasky</a>
        </div>
        <div class="navbar-collapse collapse">
            <ul class="nav navbar-nav">
                <li><a href="/">Home</a></li>
            </ul>
        </div>
    </div>
</div>
{% endblock %}

{% block content %}
<div class="container">
    <div class="page-header">
        <h1>Hello, {{ name }}!</h1>
    </div>
</div>
{% endblock %}

但这是我得到的结果:

flasky-sample

0 个答案:

没有答案