Bootstrap模板自动生成? [英] Bootstrap templates auto-generated?

查看:240
本文介绍了Bootstrap模板自动生成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在设置Flask-bootstrap时遇到了麻烦。从官方文档,似乎我所要做的就是应用Bootstrap构造函数添加到我的 app 中,模板将自动创建。所以我试过这个:

  from flask import Flask 
from flask.ext.bootstrap import Bootstrap

app = Flask(__ name__)
Bootstrap(app)

@ app.route('/')
def index():
return'< ; h1> Where Bootstrap?< / h1>'

if __name__ =='__main__':
app.run(debug = True)

当我运行它时,没有新的目录被创建,我发现任何地方都没有基础模板。我错过了关键的一步?是否有一些目录要先创建(我试图创建模板静态并将权限设置为777,但didn没有帮助)?或者基本模板是首先从命令行生成的?

你安装的包。您可以扩展boostrap base模板并覆盖其中的块,以创建一个具有标准布局的页面。你仍然需要编写引导相关的标记。这在你链接的文档中解释正确。



my_project / templates / my_page.html

  {%extendsbootstrap / base.html%} 
{%block title%}这是一个示例页面{%endblock%}

{%block navbar%}
< div class =navbar navbar-fixed-top>
<! - ... - >
< / div>
{%endblock%}

{%block content%}
< h1> Hello,Bootstrap< / h1>
{%endblock%}


I'm having trouble setting up Flask-bootstrap. From the official documentation, it seems like all I have to do is apply the Bootstrap constructor to my app, and the templates will be automatically created. So I tried this:

from flask import Flask
from flask.ext.bootstrap import Bootstrap

app = Flask(__name__)
Bootstrap(app)

@app.route('/')
def index():
    return '<h1>Where is Bootstrap?</h1>'

if __name__ == '__main__':
    app.run(debug=True)

When I run it, no new directories are created and I find no base templates anywhere. Am I missing a critical step? Is there some directory to be created first (I tried creating templates and static and setting the permissions to 777 but that didn't help)? Or perhaps the base templates are first to be generated from the command line?

解决方案

The base templates are part of the Flask-Bootstrap package you installed. You extend the boostrap base template and override the blocks in it to create a page with a standard layout. You still need to write bootstrap related markup. This is explained right in the docs you linked to.

my_project/templates/my_page.html:

{% extends "bootstrap/base.html" %}
{% block title %}This is an example page{% endblock %}

{% block navbar %}
<div class="navbar navbar-fixed-top">
  <!-- ... -->
</div>
{% endblock %}

{% block content %}
  <h1>Hello, Bootstrap</h1>
{% endblock %}

这篇关于Bootstrap模板自动生成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆