Search code examples
pythonflaskpycharmjinja2

jinja2 template not found and internal server error


Python code:

from flask import Flask, render_template

app = Flask(__name__)

@app.route("/")

def hello():

    return render_template('testing.html')

if __name__ == "__main__":
    app.run()

Html file:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>My name is pk</h1>
</body>
</html>

Also how to enable jinja2 in pycharm community version. I am directly creating html file and .py file in the same project


Solution

  • flask file structure

    |-app
    |--templates // where your html files must be in
    |--static // where your js and css files must be in
    |--.py files
    |--other packages
    

    Also jinja2 is in your python environment, if you have already installed flask.