首页 > 解决方案 > 烧瓶模板在 zeit 上呈现 500 错误

问题描述

您好我正在尝试使用 Python 和 Flask 创建我的网站,但它返回 500 错误。

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)

文件夹结构:

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"]

例外:

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

标签: pythonflask

解决方案


尝试使用其他端口号(例如 8080)运行

如果名称=='':app.run(主机='0.0.0.0',端口=8080,调试=真)


推荐阅读