[英]Flask url_for passing arguments error while extracting returns values from a form
所以我实现了这段代码:
from flask import Flask, render_template,redirect,url_for
from flask.globals import request
from task2_code import predict_num_new_cases as p
app=Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/Task1')
def Task1():
return render_template('Task 1.html')
@app.route('/Task2', methods=['GET','POST'])
def Task2():
render_template('Task 2.html')
if request.method=='POST' or request.method=='GET':
nvax=request.form.get('nvax')
po=request.form.get('pop')
co=request.form.get('c')
return redirect(url_for('display',novax=nvax,pop=po,country=co))
else:
return render_template('Task 2.html')
@app.route('/pdfview1')
def pdffor1():
return render_template
@app.route('/Task 2/display')
def display(novax,pop,country):
predicted=p(novax,pop,country)
return render_template('display.html',predicted)
@app.route('/bibliography')
def bibliography():
render_template('bibliography.html')
'''def functionultimate(no_cases,population):
#calculate stuff
return #a string value that can be concatenated into task 2'''
if __name__=="__main__":
app.run(debug=True)
但它会引发以下错误:
TypeError: display() missing 3 required positional arguments: 'novax', 'pop', and 'country'
My goal is to pass in arguments into the display function such that it invokes another function from task2_code and displays the result in display.html How else do I pass in arguments for the display function?
参数是通过请求传入的,因此您必须从请求中提取它们。 尝试这样的事情。
@app.route('/Task 2/display')
def display():
novax = request.args.get('novax')
pop = request.args.get('pop')
country = request.args.get('country')
predicted=p(novax,pop,country)
return render_template('display.html',predicted)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.