我试图在 venv 中运行一个 Flask 应用程序
python app.py
,但由于某种原因它没有运行,没有错误,但什么也没有发生,除此之外,当我单独运行 index.html 时,jinja 不会不工作,我明白了
{% extends "layout.html" %} {% block title %}search{% endblock title %} {% block body %}
(a text input and a button)
{% endblock body %}
所以也许我的layout.html或jinja有问题,这是我的layout.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{% block title %}{% endblock title %}</title>
</head>
<body>
<header>
<a id="searchlink" href="index.html" class="active">Text search</a>
<a id="imagelink" href="image.html">Images search</a>
<a id="advansedlink" href="advansed.html">Advansed search</a>
</header>
{% block body %}{% endblock body %}
</body>
</html>
这是我的index.html
{% extends "layout.html" %}
{% block title %}search{% endblock title %}
{% block body %}
<form action="https://www.google.com/search">
<input type="text" name="q">
<input type="submit" value="Google Search">
</form>
{% endblock body %}
和app.py文件
from flask import Flask, request, render_template
app = Flask(__name__)
@app.route("/")
def index():
return render_template("index.html")
if __name__ == "__main__":
app.run(debug=True)