如何用瓶子显示 'ABCMeta' 对象?分数的数据类型是什么?

How do I display 'ABCMeta' object with bottle? What is the data type of fractions?

我想将分数数据类型显示为瓶子

index.py

# -*- coding:utf-8 -*-
from fractions import Fraction
from bottle import route, view

@route('/')
@view("index_template")

def index():
    f = Fraction(3, 4)
    return dict(type(f))

index.template

{{f}}

Apache 错误日志

TypeError: 'ABCMeta' object is not iterable


环境

・分 OS 6 ・Python3.6 ・阿帕奇 2.2 ・mod_wsgi-4.5 ・瓶子 0.13 ・Chrome62

只是 return 分数对象的字符串表示形式。例如,

@route('/')
def index():
    f = Fraction(3, 4)
    return str(f)

此外(仅供参考):除非您在源代码中包含非 ascii 字符,否则 # -*- coding:utf-8 -*- 不是必需的。


EDIT: OP 表示 s/he 想要 return 分数对象的 type,不是它的价值。在这种情况下,只需 return 类型(作为字符串)。

@route('/')
def index():
    f = Fraction(3, 4)
    return str(type(f))

编辑 #2:OP 是(我猜)使用浏览器进行测试,响应呈现为 html,这让OP,因为页面显示为空白。要解决此问题,我建议 return 发送文本回复,如下所示:

from bottle import response

@route('/')
def index():
    f = Fraction(3, 4)
    response.content_type = 'text/plain' 
    return str(type(f))