【问题标题】:How can I output int type in web browser using mod_wsgi and Bottle?如何使用 mod_wsgi 和 Bottle 在 Web 浏览器中输出 int 类型?
【发布时间】:2017-05-25 15:09:20
【问题描述】:

对于字符串,是输出

from bottle import route

@route('/')
def index():
    return '4'

如果是int,则不输出

·为什么?

from bottle import route

@route('/')
def index():
    return 4

环境

・Python 3.6

・bottel 0.13

・铬

【问题讨论】:

  • FWIW,HTTP 请求无论如何都不能返回“int”; HTTP 响应是纯文本。我不知道瓶子是否会丢弃非字符串返回类型,或者是否有其他原因......

标签: python bottle


【解决方案1】:

代码没有问题

from bottle import route

@route('/')
def index():
    return '4'

@route('/')
def index2():
    return 4

print("type of ", index()," is ", type(index()))
print("type of ", index2()," is ", type(index2()))

我得到了结果:

type of  4  is  <class 'str'>
type of  4  is  <class 'int'>

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-04-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-12-13
  • 1970-01-01
  • 2013-12-18
相关资源
最近更新 更多