template won't work on Heroku
EDIT: I think it might be related to the comments posted here
Let me also add that I did not push this up in a virtualenv because I have anaconda installed for Ipython and supposedly those don't play nice together... This is another possible root of the problem
I'm attempting to deploy a flask app that runs fine locally and on foreman but gives a 500 error when deployed on heroku. It connects to my db and prints anything i tell it to up until render_template in my initial method.
Here is my stack trace.
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
it connects to the db fine and into the index method but fails on the render template....
Here is my code:
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')
my file structure is flat:
app/
--app.y
--requirements.txt
--Procfile
---static/
---templates/
And my requirements.txt has in it:
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
whats weird is that i don't get a jinga error about not finding the template... it's an os error about not finding a file... Any ideas?
链接地址: http://www.djcxy.com/p/71896.html上一篇: 只允许一个烧瓶请求一个特定的路线
下一篇: 模板在Heroku上不起作用