-1

Hi I am trying to create my site using Python and Flask, but it returns 500 error.

from flask import Flask
from flask import render_template

app = Flask(__name__, template_folder='files')

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

if __name__ == '__main__':
   app.run(debug = True)

Folder structure:

appdir
 -myapp.py
 +files
  -index.html

Dockerfile:

FROM python:3-alpine
WORKDIR /usr/src
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
ENV GUNICORN_CMD_ARGS="--bind=0.0.0.0"
CMD ["gunicorn", "myapp:app"]

Exception:

File "/usr/local/lib/python3.7/site-packages/flask/templating.py", line 86, in _get_source_fast
10/22 01:38 PM (2m)
    raise TemplateNotFound(template)
10/22 01:38 PM (2m)
jinja2.exceptions.TemplateNotFound: index.html
awesoon
  • 32,469
  • 11
  • 74
  • 99
rumo
  • 1
  • 3
  • Any logs? Error message in the response? – awesoon Oct 22 '18 at 10:26
  • [2018-10-22 10:14:00,800] ERROR in app: Exception on /projects [GET] 10/22 01:14 PM (15m) File "/usr/local/lib/python3.7/site-packages/flask/templating.py", line 86, in _get_source_fast 10/22 01:14 PM (15m) raise TemplateNotFound(template) 10/22 01:14 PM (15m) jinja2.exceptions.TemplateNotFound:index.html – rumo Oct 22 '18 at 10:29
  • @rumo Please add that information to the question – DarkSuniuM Oct 22 '18 at 10:33
  • @rumo Also please include information about the command you are using to start the application – awesoon Oct 22 '18 at 10:36
  • FROM python:3-alpine WORKDIR /usr/src COPY requirements.txt . RUN pip install -r requirements.txt COPY . . ENV GUNICORN_CMD_ARGS="--bind=0.0.0.0" CMD ["gunicorn", "myapp:app"] – rumo Oct 22 '18 at 10:39
  • yes please check – rumo Oct 22 '18 at 10:41
  • I have just copied your code, working fine: https://imgur.com/REKDRER . Are you sure `index.html` is copying to docker image and not ignored by `.dockerignore` or something else? – awesoon Oct 22 '18 at 11:23
  • @soon very interesting – rumo Oct 22 '18 at 11:41

1 Answers1

0

try running with some other port number such as 8080

if name == 'main': app.run(host='0.0.0.0', port=8080,debug = True)

Rajesh Sahoo
  • 1
  • 1
  • 2