I am calling a function from another fuction.
The function I am calling
@app.route('/csv/')
def download_csv(p):
csv = p
response = make_response(csv)
cd = 'attachment; filename=RosterUnified.csv'
response.headers['Content-Disposition'] = cd
response.mimetype='text/csv'
return response
In my HTML this is associated with a button click 'Download'.
I am calling this from within:
@app.before_request
def ros_before_app():
.
.
.
z=open(Filename1)
with z as f:
p = f.read()
download_csv(p)
z.close()
else:
z1=open(Filename)
with z1 as f1:
p = f1.read()
download_csv(p)
The console gives the error:
return self.view_functions[rule.endpoint](**req.view_args)
TypeError: download_csv() missing 1 required positional argument: 'p'
and the 'Download' button on click gives download failed, server problem
In Flask the @app.route('/')
decorator must contain any arguments that are passed into the function. You can do this by adding a <var>
tag to the url. So the code you have might look like this,
@app.route('/csv/<p>')
def download_csv(p):
csv = p
# continue code here...
Variable, csv
equals file
if the URL is .../csv/file
. Notice how instead of saying <p>
we put in an argument that got passed into the function.
For even more infromation on variable passing in this decorator, look at Flask's Variable Rules.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments