【问题标题】:jinja2.exceptions.TemplateNotFound [duplicate]jinja2.exceptions.TemplateNotFound [重复]
【发布时间】:2016-09-24 17:34:48
【问题描述】:

我的项目中有以下结构: \我的应用 应用程序.py \包括
你好.html 所以文件夹 myapp 包含 application.py 并且文件夹包含。 该文件夹包含 hello.html。 以下代码: 应用程序.py

#!/usr/bin/python 2.7.6
# -*- coding:utf-8 -*-
import os
import sys
from flask import Flask,render_template
import psycopg2
app = Flask(__name__)

@app.route('/')
def fihoum():
    conn = psycopg2.connect(database="carto", user="postgres",
           password="daed5Aemo", host="192.168.12.54")
    cur = conn.cursor()
    cur.execute("SELECT * FROM carto.\"BADGES_SFR\"")
    rows = cur.fetchall()
    return render_template('hello.html', titre="Données du client
   BADGES_SFR !",mots=rows)

if __name__=="__main__":
    app.run(host=os.getenv('IP', '0.0.0.0'), 
            port=int(os.getenv('PORT',5000)),debug=True)

下面的代码hello.html:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title>{{ titre }}</title>
    </head>

    <body>
        <h1>{{ titre }}</h1>
        <ul>
        {% for mot in mots %}
            <li>{{ mot }}</li>
        {% endfor %}
        </ul>
    </body>
</html>

问题:当我运行程序 application.py 我有这个错误: jinja2.exceptions.TemplateNotFound

模板未找到:hello.html 感谢您的帮助

【问题讨论】:

    标签: python flask


    【解决方案1】:

    模板文件夹默认为templates\;所以你应该将include 重命名为templates

    【讨论】:

      猜你喜欢
      • 2013-02-09
      • 2018-04-16
      • 2020-03-20
      • 2018-12-02
      • 1970-01-01
      • 1970-01-01
      • 2017-11-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多