Flask render_template不能在Heroku上工作

时间:2014-07-28 17:19:59

标签: python heroku deployment flask jinja2

修改 我认为这可能与to the comments posted here

有关

我还要补充一点,因为我为Ipython安装了anaconda,并且据说那些不能在一起玩得很好,所以我没有把它推到一个虚拟环境中......这是问题的另一个可能根源


我试图部署一个在本地和工头上运行良好的烧瓶应用,但在heroku上部署时会出现500错误。它连接到我的数据库并打印我告诉它的任何内容,直到我的初始方法中的render_template。

这是我的堆栈跟踪。

Traceback (most recent call last):
    response = self.full_dispatch_request()
    reraise(exc_type, exc_value, tb)
  File "/app/.heroku/python/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
    rv = self.handle_user_exception(e)
    reraise(exc_type, exc_value, tb)
    context, ctx.app)
  File "/app/.heroku/python/lib/python2.7/site-packages/flask/templating.py", line 128, in render_template
  File "/app/.heroku/python/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
    return render_template('/index.html')
  File "/app/.heroku/python/lib/python2.7/site-packages/jinja2/environment.py", line 742, in handle_exception
  File "/app/.heroku/python/lib/python2.7/site-packages/webassets/bundle.py", line 685, in urls
  File "/app/.heroku/python/lib/python2.7/site-packages/webassets/ext/jinja2.py", line 181, in _render_assets
  File "/app/.heroku/python/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
  File "/app/.heroku/python/lib/python2.7/site-packages/jinja2/environment.py", line 969, in render
    urls = bundle.urls(env=env)
  File "/app/.heroku/python/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
  File "/app/templates/index.html", line 10, in top-level template code
    reraise(exc_type, exc_value, tb)
    rv = template.render(context)
  File "/app/.heroku/python/lib/python2.7/site-packages/webassets/bundle.py", line 504, in _build
    force, disable_cache=disable_cache, extra_filters=extra_filters)
  File "/app/.heroku/python/lib/python2.7/site-packages/webassets/merge.py", line 219, in _wrap_cache
  File "/app/.heroku/python/lib/python2.7/site-packages/flask/templating.py", line 110, in _render
    getattr(filter, type)(data, out, **kwargs_final)
  File "/app/.heroku/python/lib/python2.7/site-packages/webassets/bundle.py", line 429, in _merge_and_apply
  File "/app/.heroku/python/lib/python2.7/site-packages/webassets/merge.py", line 272, in apply
  File "/app/.heroku/python/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
  File "/app/.heroku/python/lib/python2.7/site-packages/webassets/filter/sass.py", line 122, in _apply_sass
    return self.environment.handle_exception(exc_info, True)
    rv = self.dispatch_request()
    errread, errwrite)
  File "/app/.heroku/python/lib/python2.7/subprocess.py", line 1327, in _execute_child
    kwargs=item_data)
    *args, **kwargs)
  File "/app/.heroku/python/lib/python2.7/subprocess.py", line 710, in __init__
  File "/app/.heroku/python/lib/python2.7/site-packages/webassets/bundle.py", line 647, in _urls
    return self._wrap_cache(key, func)
    raise child_exception
  File "/app/.heroku/python/lib/python2.7/site-packages/webassets/filter/sass.py", line 141, in input
    self._apply_sass(_in, out, os.path.dirname(source_path))
    return self.view_functions[rule.endpoint](**req.view_args)
    content = func().getvalue()
  File "/app/.heroku/python/lib/python2.7/site-packages/webassets/merge.py", line 252, in func
  File "/app/app.py", line 110, in index
    shell=(os.name == 'nt'))
OSError: [Errno 2] No such file or direct

它连接到db fine并进入index方法,但在渲染模板上失败....

这是我的代码:

import os
from urlparse import urlparse
import unicodedata
import time

from datetime import datetime, date
from bs4 import BeautifulSoup
from urllib2 import urlopen
from ast import literal_eval
from flask import Flask, jsonify, render_template, request
from flask.ext import assets
# from flask.ext.pymongo
import pymongo

app = Flask(__name__)
app.debug = True

app.config['MONGO_USERNAME'] = 'email'
app.config['MONGO_PASSWORD'] = 'password'
app.config['MONGO_DBNAME'] = 'app22343276'

MONGO_URL = os.environ.get('MONGOHQ_URL')


if MONGO_URL:
    # Get a connection
    mongo = pymongo.Connection(MONGO_URL)
    # Get the database
    db = mongo[urlparse(MONGO_URL).path[1:]]
else:
    # Not on an app with the MongoHQ add-on, do some localhost action
    mongo = pymongo.Connection('localhost', 27017)
    # mongo = pymongo(app)
    db = mongo['mongoData']


env = assets.Environment(app)
# print "past mongo"
# Tell flask-assets where to look for our coffeescript and sass files.
env.load_path = [
    os.path.join(os.path.dirname(__file__), 'bootstrap/css'),
    os.path.join(os.path.dirname(__file__), 'sass'),
    os.path.join(os.path.dirname(__file__), 'coffee'),
    os.path.join(os.path.dirname(__file__), 'bower_components'),
]


env.register(
    'js_all',
    assets.Bundle(
        'jquery/dist/jquery.min.js',
        'bootstrap.min.js',
        'd3.min.js',
        'dc.js',
        'crossfilter.js',
        'colorbrewer.js',
        assets.Bundle(
            'all.coffee',
            'chartFunctions.coffee',
            'helpers.coffee', 
            'listeners.coffee',
            'dashboardClass.coffee',
            'chartClass.coffee',
            #'three.coffee',
            #'map.coffee',
            #'all.coffee',
            filters=['coffeescript']
        ), 
        output='js_all.js'
    )
)

env.register(
    'css_all',
    assets.Bundle(
        'all.sass',
        filters=['sass','scss'],
        output='css_all.css'
    )
)
print "right before app.route"
# print os.environ.get(__name__)

@app.route("/")
def index():
    print db
    print "in index"
    print os.getcwd()
    return render_template('/index.html')

我的文件结构是扁平的:

app/
    --app.y
    --requirements.txt
    --Procfile
    ---static/
    ---templates/

我的requirements.txt包含在其中:

Flask==0.10.1
Flask-Assets==0.9
Jinja2==2.7.2
Werkzeug==0.9.4
beautifulsoup4==4.3.1
html5lib==0.999
pymongo==2.7.1
python-dateutil==1.5

有点奇怪的是,我没有找到关于找不到模板的错误信息...这是一个关于找不到文件的错误......任何想法?

0 个答案:

没有答案
相关问题