b中没有值的参数

2024-04-26 03:04:26 发布

您现在位置:Python中文网/ 问答频道 /正文

在我的钩子/路线中,我使用:

debug = request.GET.get('debug', False)

它与:

http://test.internal.local:8888/probe?debug=anything

但是我怎样才能让它只使用标志而不使用类似的值呢?你知道吗

http://test.internal.local:8888/probe?debug

谢谢


Tags: debugtestfalsehttpgetrequest标志local
1条回答
网友
1楼 · 发布于 2024-04-26 03:04:26

您仍然可以获得debug标志,但值将是空字符串('')。你知道吗

所以检查一下你的旗子是否简单:

debug = request.GET.get('debug')  # if there is no debug flag you get `None`
if debug is not None:
    # you have your debug flag

相关问题 更多 >