Forums

Unable To Render Template

appname/mysite/<br> ------------------------/templates<br> -----------------------/static<br> -----------------------flask_app.py

from flask import Flask, render_template
app = Flask(__name__)

@app.route('/')
def index():
    return render_template('index.html')

if __name__ == "__main__":
    app.run(debug=True,host='0.0.0.0')

this was the flask_app.py and inside templates there is a file index.html the wgsi config file looks like<br>

import sys


project_home = u'/home/indrajeetbday/mysite/'
if project_home not in sys.path:
    sys.path = [project_home] + sys.path


from flask_app import app as application

application.run(debug=True,host='0.0.0.0')

But when i try to launvh the app it shows Error code: Unhandled Exception <br> And the error log looks something like: <br>

2015-09-22 04:50:40,435 :Traceback (most recent call last):
2015-09-22 04:50:40,436 :  File "/bin/user_wsgi_wrapper.py", line 134, in __call__
2015-09-22 04:50:40,436 :    self.error_log_file.logger.exception("Error running WSGI application")
2015-09-22 04:50:40,436 :  File "/usr/lib/python2.7/logging/__init__.py", line 1185, in exception
2015-09-22 04:50:40,436 :    self.error(msg, *args, **kwargs)
2015-09-22 04:50:40,437 :  File "/usr/lib/python2.7/logging/__init__.py", line 1178, in error
2015-09-22 04:50:40,437 :    self._log(ERROR, msg, args, **kwargs)
2015-09-22 04:50:40,438 :  File "/usr/lib/python2.7/logging/__init__.py", line 1270, in _log
2015-09-22 04:50:40,438 :    record = self.makeRecord(self.name, level, fn, lno, msg, args, exc_info, func, extra)
2015-09-22 04:50:40,438 :  File "/usr/lib/python2.7/logging/__init__.py", line 1244, in makeRecord
2015-09-22 04:50:40,439 :    rv = LogRecord(name, level, fn, lno, msg, args, exc_info, func)
2015-09-22 04:50:40,439 :  File "/usr/lib/python2.7/logging/__init__.py", line 284, in __init__
2015-09-22 04:50:40,439 :    self.threadName = threading.current_thread().name
2015-09-22 04:50:40,439 :  File "/usr/lib/python2.7/threading.py", line 1160, in currentThread
2015-09-22 04:50:40,439 :    return _active[_get_ident()]
2015-09-22 04:50:40,439 :  File "/bin/user_wsgi_wrapper.py", line 126, in __call__
2015-09-22 04:50:40,439 :    app_iterator = self.app(environ, start_response)
2015-09-22 04:50:40,440 :  File "/bin/user_wsgi_wrapper.py", line 140, in import_error_application
2015-09-22 04:50:40,440 :    raise e
2015-09-22 04:50:40,440 :OSError: [Errno 2] No such file or directory

I have to say that's rather baffling... If you're not too far on in your experiments with Flask, would you be able to try deleting your web app and all your code, and just starting again from scratch?

just add import os to your wsgi script