flask calling a function from another

ananda

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

Preston Hager

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Calling a function from another package

From Dev

Calling a function from another in ReactJs

From Dev

Calling a function from another Project

From Dev

Calling a function from another process

From Dev

Calling a function from another class?

From Dev

Python calling function in an function from another function

From Dev

Calling REST API of a Flask app from another Flask app

From Dev

Calling function with object parameter from another function

From Dev

Calling main function from another function in C

From Dev

Calling a class function from within another function

From

Calling init function from another function

From Dev

Calling a function from another function in typescript

From Dev

Calling the BlogEntries function from another function [SilverStripe]

From Dev

Calling a Function From Another Function in PowerShell

From Dev

Python calling a function from another function in a class

From Dev

Calling php function from inside another function

From Dev

Error when calling function from another function

From Dev

Calling a function from inside another function?

From Dev

Calling variable from one function into another function

From Dev

Use a variable from a function in another function, with flask

From Dev

Calling a Future Function from another screen in Flutter

From Dev

PHP calling function from another file not working

From Dev

Calling function from another class (React)

From

Calling a function from another file fails

From Dev

Kotlin: Calling a function from another class

From Dev

Calling an assembly function from another file

From Dev

Octave calling function from another m file

From Dev

Calling ViewController function from another .swift file

From

Calling a variable from another function in go

Related Related

  1. 1

    Calling a function from another package

  2. 2

    Calling a function from another in ReactJs

  3. 3

    Calling a function from another Project

  4. 4

    Calling a function from another process

  5. 5

    Calling a function from another class?

  6. 6

    Python calling function in an function from another function

  7. 7

    Calling REST API of a Flask app from another Flask app

  8. 8

    Calling function with object parameter from another function

  9. 9

    Calling main function from another function in C

  10. 10

    Calling a class function from within another function

  11. 11

    Calling init function from another function

  12. 12

    Calling a function from another function in typescript

  13. 13

    Calling the BlogEntries function from another function [SilverStripe]

  14. 14

    Calling a Function From Another Function in PowerShell

  15. 15

    Python calling a function from another function in a class

  16. 16

    Calling php function from inside another function

  17. 17

    Error when calling function from another function

  18. 18

    Calling a function from inside another function?

  19. 19

    Calling variable from one function into another function

  20. 20

    Use a variable from a function in another function, with flask

  21. 21

    Calling a Future Function from another screen in Flutter

  22. 22

    PHP calling function from another file not working

  23. 23

    Calling function from another class (React)

  24. 24

    Calling a function from another file fails

  25. 25

    Kotlin: Calling a function from another class

  26. 26

    Calling an assembly function from another file

  27. 27

    Octave calling function from another m file

  28. 28

    Calling ViewController function from another .swift file

  29. 29

    Calling a variable from another function in go

HotTag

Archive