参数没有价值瓶
问题描述:
在我的钩/路线我用:参数没有价值瓶
debug = request.GET.get('debug', False)
而且它的工作原理:
http://test.internal.local:8888/probe?debug=anything
,但我怎么才能得到它只有在标志和没有价值的工作喜欢?
http://test.internal.local:8888/probe?debug
感谢
答
你仍然可以得到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
大它的作品,如果我用'如果调试是':'而不是'如果调试:'也许我应该更改默认为“” ?。谢谢 – MortenB
我相信它更容易阅读。 'request.GET.get('debug')'你知道你得到了什么('None'),如果没有提供该标志,并且'if'-语句非常清晰。 –