英文:
Drivehandler: Modify: Is it possible to keep the `GET` request same as default, but only modify the `POST `
问题
保持帮助文档中的默认配置,我们有
url:
drivehandler:
pattern: /$YAMLURL/drive
handler: DriveHandler
kwargs:
path: $YAMLURL/drive
modify: mymodule.modify(handler)
mymodule.py
被创建为:
def modify():
if handler.request.method.upper() == "POST":
import pandas as pd
data = []
for d in pd.DataFrame(handler.files).itertuples():
print("预处理的数据", d)
Gramex 服务器在默认端口运行,POST
运行良好,在浏览器控制台中我们得到打印语句的输出。
然而,当我们尝试 GET
localhost:9988/drive
时;虽然 drive/.meta.db 已填充,但结果始终为空。
所以想知道如果我修改了 POST
请求,我是否也需要创建一个自定义修改来处理 GET
请求?
英文:
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
得分: 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("preprocessed data", d)
else:
return data
You would also need to modify gramex.yaml
to reflect the data
argument:
modify: mymodule.modify(handler, data)
英文:
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)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论