Flask-Assets 在本地工作但不在 Heroku 上工作
Flask-Assets working locally but not on Heroku
我正在努力修改 cookiecutter Flask app. I'm working locally on WIN7 and attempting to deploy to heroku. I'm currently trying to add a datepicker to a page. I've found https://eonasdan.github.io/bootstrap-datetimepicker/。 myflaskapp 的结构:
我已经设置了 bower 以在静态根目录下安装前端依赖项,方法是使用文档根目录中的 .bowerrc 文件,其中包含:
{ "directory" : "myflaskapp/static/bower_components" }
这个 cookiecutter 使用 flask-assets 来管理项目资产。在 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,这可能与此有关。
尝试检查您的 .gitignore,构建通常会被忽略,这会在此处排除您的静态文件:bower_components/eonasdan-bootstrap-datetimepicker/build/*
我正在努力修改 cookiecutter Flask app. I'm working locally on WIN7 and attempting to deploy to heroku. I'm currently trying to add a datepicker to a page. I've found https://eonasdan.github.io/bootstrap-datetimepicker/。 myflaskapp 的结构:
我已经设置了 bower 以在静态根目录下安装前端依赖项,方法是使用文档根目录中的 .bowerrc 文件,其中包含:
{ "directory" : "myflaskapp/static/bower_components" }
这个 cookiecutter 使用 flask-assets 来管理项目资产。在 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,这可能与此有关。
尝试检查您的 .gitignore,构建通常会被忽略,这会在此处排除您的静态文件:bower_components/eonasdan-bootstrap-datetimepicker/build/*