模板在Heroku上不起作用

编辑:我想这可能与这里发布的评论有关

我还要补充一点,我没有在virtualenv中推动它,因为我为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

它连接到数据库罚款和进入索引方法,但失败的渲染模板....

这是我的代码:

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

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

链接地址: http://www.djcxy.com/p/71895.html

上一篇: template won't work on Heroku

下一篇: How to use Flask's render