Routing 在服务器中像字符串一样传递路径

Routing 在服务器中像字符串一样传递路径,routing,hug,Routing,Hug,是否有任何方法可以在拥抱中传递带有斜杠的字符串,例如使用此函数: import hug @hug.get("/returnfilecontent/{path}") def doubles(path): return open(path, 'r').read() 我想访问http://localhost/returnfilecontent/foo/bar/myfile.md从位于foo/bar/myfile.md的文件中读取内容 似乎拥抱不支持路径,我只能传递非路径字符串,如http:

是否有任何方法可以在拥抱中传递带有斜杠的字符串,例如使用此函数:

import hug

@hug.get("/returnfilecontent/{path}")
def doubles(path):
    return open(path, 'r').read()
我想访问
http://localhost/returnfilecontent/foo/bar/myfile.md
从位于
foo/bar/myfile.md的文件中读取内容


似乎拥抱不支持路径,我只能传递非路径字符串,如
http://localhost/returnfilecontent/myfile.md

我不确定这是否是您要找的,这是否有帮助

导入
@hug.get(“/returnfilecontent”)
def加倍(请求,路径:hug.types.text):
返回open(路径'r')。read()
您可以通过调用此get请求

curlhttp://localhost:8000/returnfilecontent/\?路径\=foo\/bar\/myfile.md
或者您可以尝试将它们作为foo_bar_myfile.md传入,然后拆分并加入它,使其成为路径

还是像这样

导入
@get(“/returnfilecontent/{base\u path}/{middle\u folder}/{filename}”)
def加倍(请求,基本路径:hug.types.text,中间文件夹,文件名):
返回f“{base_path}/{middle_folder}/{filename}”

Mmm。这不是我想要的。我想我想用
创建一个类似字符串的路径?path\=foo\/bar\/myfile.md
不适合我。请验证答案。我用了curl。您可以在函数中获取任何作为路径发送的内容