【发布时间】:2019-02-12 14:23:55
【问题描述】:
我想使用带有“from”和“to”日期的 URL,也可以只提供两个参数之一。因此,我需要通过关键字知道是否只提供了一个参数,如果它是“从”或“到”日期。
如何设置 URL,以便我可以检查是否提供了任何一个参数并将它们用作相应类中的变量?
这些线程没有解决我的问题:flask restful: passing parameters to GET request 和 How to pass a URL parameter using python, Flask, and the command line。
class price_history(Resource):
def get(self, from_, to):
if from_ and to:
return 'all data'
if from_ and not to:
return 'data beginning at date "from_"'
if not from_ and to:
return 'data going to date "to"'
if not from_ and not to:
return 'please provide at least one date'
api.add_resource(price_history, '/price_history/from=<from_>&to=<to>')
【问题讨论】: