首页 > 解决方案 > render_template 在 aws beanstalk 中给出内部服务器错误

问题描述

我正在尝试在 AWS elasticbeanstalk 中托管一个简单的应用程序,但是当我使用 render_template 它给我这个错误“内部服务器错误服务器遇到内部错误并且无法完成您的请求。服务器过载或存在应用程序中的错误。”

这是我的烧瓶代码,

from flask import Flask, render_template
import requests

application = Flask(__name__, template_folder="templates", static_folder="static")

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

# run the app.
if __name__ == "__main__":
    application.debug = True
    application.run()

我的 HTML 代码,

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>

<div>
    <h1>Hello, Flask!</h1>
</div>

</body>
</html>

我的目录结构,

templates
  |
   ------> index.html
application.py
requirments.txt

但是当我不使用 render_template 时,我没有看到任何问题,这是代码,

from flask import Flask, render_template
import requests

application = Flask(__name__, template_folder="templates", static_folder="static")

@application.route("/")
def index():
    return "Hello Flask!!"

# run the app.
if __name__ == "__main__":
    application.debug = True
    application.run()

先感谢您。

标签: pythonamazon-web-servicesflaskamazon-elastic-beanstalkjinja2

解决方案


编辑 -

我能够解决这个问题,问题出在我创建的 zip 文件夹上。一旦我创建了一个适当的 zip 并将其上传到 aws beanstalk,它就开始工作了。


推荐阅读