我有一个表单值:
anytext = request.POST.get("my_text", None)
if anytext and anytext.is_string:
perform any action
if anytext and anytext.is_numeric:
perform another action
如何检查数值??
最佳答案
如果isdigit()
总是anytext
类型,则可以使用string
。
例如:
'Hello World'.isdigit() # returns False
'1234243'.isdigit() # returns True
所以你的代码:
anytext = request.POST.get("my_text", "")
if anytext.isdigit():
# perform action on numeric string
else:
# perform action on alphanumeric string