在部署到Heroku时,为什么赢得烧瓶应用导入flask-bootstrap base.html模板?

时间:2017-08-08 20:20:51

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

我在本地计算机上工作没有问题但是当部署到Heroku时,flask-bootstrap资产不会导入位于虚拟环境中的base.html文件。我无法在日志或控制台中发现任何错误。

我是否仍然需要在Heroku上激活虚拟环境,或者是否已经处理好了?

这是我尝试导入bootsrap的config.py文件:

@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "yourEmbeddedIdAtribute")

app.py导入文件并激活服务器

from flask import Flask
from flask_bootstrap import Bootstrap
from flask_sqlalchemy import SQLAlchemy

app = Flask(__name__)
Bootstrap(app)
db = SQLAlchemy(app)

app.config['SQLALCHEMY_DATABASE_URI'] = 'URI-is-changed-on-this-question-for-privacy-reasons'

app.config['SECRET_KEY'] = 'secret-key-is-changed-on-this-website-for-privacy reasons' 

这是尝试扩展boostrap base.html的html文件

from config import app
from flask import Flask
from models import authentication, posts
from views import authentication, posts
from forms import authentication, posts

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

这里是base.html文件,它位于路径上的虚拟环境中' ./ venv / Lib / site-packages / flask_bootstrap / templates / bootstrap / base.html'

{% extends "bootstrap/base.html" %}
{% import "bootstrap/wtf.html" as wtf %}

{% block jumbotron %}
    <div class="jumbotron">
        <h2>Hunter Krieger</h2>
        <h3>Blogger, Web Developer, Gamer and Bibliophile
    </div>
{% endblock jumbotron %}

{% block content %}
    {% if post %}
        {% for display in post %}
            <article class="well">
                <h1><a href="/{{ display.slug }}">{{ display.title }}</a></h1>
                <h4>Written by {{ display.author }}</h4>
                <h4>{{ display.created_at.strftime('%b %d, %Y') }}</h4>
                <div class="body">
                    {{ display.body | truncate(1250) | safe }}
                </div>
            </article>
        {% endfor %}
    {% else %}
        <p>There are no posts</p>
    {% endif %}
{% endblock %}

从看到代码有没有人知道我可以改变什么来让flask-bootstrap在Heroku上工作?

1 个答案:

答案 0 :(得分:0)

在您的第一个代码段中,Bootstrap(app)应为bootstrap = Bootstrap(app)

from flask import Flask
from flask_bootstrap import Bootstrap
from flask_sqlalchemy import SQLAlchemy

app = Flask(__name__)
bootstrap = Bootstrap(app)  # this line
db = SQLAlchemy(app)