Python jinja2.exceptions.UnfinedError:&x27;btn&x27;是未定义的
我收到jinja2.exceptions.UndefinedError:“btn”是登录到本地主机时未定义的异常。btn已正确定义,但仍然。。我能尽快得到帮助吗。先谢谢你 Python代码-此代码是Python代码Python jinja2.exceptions.UnfinedError:&x27;btn&x27;是未定义的,python,jinja2,Python,Jinja2,我收到jinja2.exceptions.UndefinedError:“btn”是登录到本地主机时未定义的异常。btn已正确定义,但仍然。。我能尽快得到帮助吗。先谢谢你 Python代码-此代码是Python代码 from flask import Flask, render_template, request, send_file from flask_sqlalchemy import SQLAlchemy from send_email import send_email from sq
from flask import Flask, render_template, request, send_file
from flask_sqlalchemy import SQLAlchemy
from send_email import send_email
from sqlalchemy.sql import func
from werkzeug import secure_filename
app=Flask(__name__)
@app.route("/")
def index():
return render_template("index.html")
@app.route("/success", methods=['POST'])
def success():
global file
if request.method=='POST':
file=request.files["file"]
file.save(secure_filename("uploaded" + file.filename))
with open("uploaded"+file.filename,"a") as f :
f.write("This was added later!")
return render_template("index.html", btn="download.html")
@app.route("/download")
def download():
return send_file("uploaded" + file.filename, attatchment_filename="yourfile.csv", as_attatchment=True)
if __name__ == '__main__':
app.debug=True
app.run()
HTML-
索引文件-这是主文件
<!DOCTYPE html>
<html lang="en">
<title> Data Collector App</title>
<head>
<link href="../static/main.css" rel="stylesheet">
</head>
<body>
<div class="container">
<h1>Collecting Height</h1>
<h3>Please Fill the Entries to get Population Statistics on Height</h3>
<div class="message">
{{text | safe}}
</div>
<form action="{{url_for('success')}}" method="POST" enctype="multipart/form-data">
<input type="file" name="file" > <br>
<button type="submit">Submit</button>
</form>
{%include btn ignore missing%}
</div>
</body>
</html>
数据采集器应用程序
收集高度
请填写这些条目以获取身高的人口统计数据
{{text | safe}}
提交
{%include btn ignore missing%}
下载文件-这是用于下载的html文件。导入文件后,此html代码将在同一index.html页面中创建一个按钮,以便我也可以下载同一文件
<!DOCTYPE html>
<html lang="en">
<div class="download">
<a href= {{url_for('download')}} target="blank"> <button class="btn"> Download </button></a>
</div>
</html>
也面临同样的问题。我的解决办法是替换:
{%include btn ignore missing%}
与
{%if btn%}
{%include btn%}
{%endif%}
也面临同样的问题。我的解决办法是替换:
{%include btn ignore missing%}
与
{%if btn%}
{%include btn%}
{%endif%}
请将完整的错误回溯添加到您的问题中def index():返回render_模板(“index.html”)
所需的btn模板{%include btn ignore missing%}请将完整的错误回溯添加到您的问题中def index():返回render_模板(“index.html”)
所需的btn模板{%include btn ignore missing%}