Reputation: 5870
I'm relatively new to Flask, but I'm already finding the need to use Blueprints. However, in my Blueprint, I'm trying to render a template, but getting an error.
When hooked up as a WSGI application (on Dreamhost), the render_template function returns this error:
File ".../app/ui/__init__.py", line 95, in index
response = make_response(render_template('index.html', **data))
File ".../flask/templating.py", line 123, in render_template
ctx.app.update_template_context(context)
AttributeError: 'NoneType' object has no attribute 'app'
However, when I call the app.py directly in debug mode it works perfectly! (below)
python app/app.py
In app.py:
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0')
EDIT: Rendering template:
@ui_blueprint.route('/', methods=['GET'])
@ui_blueprint.route('/home', methods=['GET'])
def index():
data = {
'title': 'Index'
}
response = make_response(render_template('index.html', **data))
return response
EDIT 2: ctx
is:
None
in the WSGI app case<RequestContext 'http://aaa.bbb.com:5000/' [GET] of __init__>
in the direct call caseAny ideas how I might fix this error? Thanks!
Upvotes: 2
Views: 3711
Reputation: 5870
When setting up Flask, make sure that all dependencies are installed correctly. That's the problem in this case.
If running on mod_wsgi, also make sure that any reads or writes are directed to the proper location; otherwise, the app make work when run using app.run()
but the paths change when using Apache.
Upvotes: 1
Reputation: 1
Make sure that you are importing all the right modules:
from flask import Flask, render_template, make_response, request, Response
And you may want to create a wrapper for your view.
Upvotes: 1