1

我正在修改一个cookiecutter Flask 应用程序。我正在本地使用 WIN7 并尝试部署到 heroku。我目前正在尝试将日期选择器添加到页面。我找到了https://eonasdan.github.io/bootstrap-datetimepicker/。myflaskapp的结构:

在此处输入图像描述

我已经设置了 bower,通过在包含以下内容的文档根目录中使用 .bowerrc 文件,在静态根目录下安装前端依赖项:

{ "directory" : "myflaskapp/static/bower_components" }

在此处输入图像描述

这个 cookiecutter 使用烧瓶资产来管理项目资产。在https://adambard.com/blog/fresh-flask-setup/之后 ,我修改了 myflaskapp/assets.py 文件:

from flask_assets import Bundle, Environment
import os

css = Bundle(
    "libs/bootstrap/dist/css/spacelab/bootstrap.css",
    "bower_components/eonasdan-bootstrap-datetimepicker/build/css/bootstrap-datetimepicker.css",
    "css/style.css",
    "css/home.css",
    # "css/style.css",
    filters="cssmin",
    output="public/css/common.css"
)

js = Bundle(
    "libs/jQuery/dist/jquery.js",
    "libs/bootstrap/dist/js/bootstrap.js",
    "bower_components/moment/moment.js",
    "bower_components/eonasdan-bootstrap-datetimepicker/build/js/bootstrap-datetimepicker.min.js",
    "js/plugins.js",
    filters='jsmin',
    output="public/js/common.js"
)


assets = Environment()

assets.register("js_all", js)
assets.register("css_all", css)

myflaskapp/app.py 初始化资产:

from flask import Flask, render_template
from myflaskapp.assets import assets
    """
    :param config_object: The configuration object to use.
    """
    app = Flask(__name__)
    app.config.from_object(config_object)
    register_extensions(app)
    register_blueprints(app)
    register_errorhandlers(app)
    return app

def register_extensions(app):
    assets.init_app(app)

def register_blueprints(app):
    app.register_blueprint(public.blueprint)
    app.register_blueprint(user.blueprint)

在 myflaskapp/settings.py 中,在测试期间,我设置了:

ASSETS_DEBUG = True  # Don't bundle/minify static assets

在本地,控制台中没有错误。在 heroku 上,我收到内部服务器错误。日志:

    ←[33m2016-03-19T18:02:12.464159+00:00 app[web.1]:←[0m     for org, cnt in self.resolve_contents(ctx):
    ←[33m2016-03-19T18:02:12.464161+00:00 app[web.1]:←[0m     raise BundleError(e)
    ←[33m2016-03-19T18:02:12.464162+00:00 app[web.1]:←[0m BundleError: 'bower_components/eonasdan-bootstrap-datetimepicker/build/css/bootstrap-datetimepicker.css' not found in load path:
    ['/app/myflaskapp/static']
    ←[33m2016-03-19T18:02:12.464150+00:00 app[web.1]:←[0m     rv = template.render(context)
    ←[33m2016-03-19T18:02:12.464151+00:00 app[web.1]:←[0m   File "/app/.heroku/python/lib/python2.7/site-packages/jinja2/environment.py", line 969, in render
    ←[33m2016-03-19T18:02:12.464152+00:00 app[web.1]:←[0m   File "/app/.heroku/python/lib/python2.7/site-packages/jinja2/environment.py", line 742, in handle_exception
    ←[33m2016-03-19T18:02:12.464154+00:00 app[web.1]:←[0m     {% extends "layout.html" %}
    ←[33m2016-03-19T18:02:12.464157+00:00 app[web.1]:←[0m     urls = bundle.urls()
    ←[33m2016-03-19T18:02:12.464153+00:00 app[web.1]:←[0m     reraise(exc_type, exc_value, tb)

正如您在顶部屏幕截图中看到的那样,它就在那里。我怎样才能解决这个问题?

注意:我一直在查看https://github.com/mitsuhiko/flask/issues/348,这可能与此有关。

4

1 回答 1

4

尝试检查您的 .gitignore,构建通常会被忽略,这会在此处排除您的静态文件:bower_components/eonasdan-bootstrap-datetimepicker/build/*

于 2016-03-22T18:16:28.630 回答