0

Keeping default config from help document we have

url:
  drivehandler:
    pattern: /$YAMLURL/drive
    handler: DriveHandler
    kwargs:
      path: $YAMLURL/drive
      modify: mymodule.modify(handler)

mymodule.py is created as:

def modify():
    if handler.request.method.upper() == "POST":
        import pandas as pd
        data = []
        for d in pd.DataFrame(handler.files).itertuples():
            print("preprocesed data", d)

And gramex server is ran in the default port, POST works great and on the browser console we get the output of the print statement.
However, when we try to GET localhost:9988/drive; Although the drive/.meta.db is populated, the result is always blank. So wondering if I modify the POST request, Do I need to create a custom modification to GET as well?

1 Answers1

0

For a GET method, this function returns None. Instead, you could use:

def modify(handler, data):
    if handler.request.method.upper() == "POST":
        import pandas as pd

        data = []
        for d in pd.DataFrame(handler.files).itertuples():
            print("preprocesed data", d)
    else:
        return data

You would also need to modify gramex.yaml to reflect the data argument:

      modify: mymodule.modify(handler, data)
S Anand
  • 11,364
  • 2
  • 28
  • 23