'Area' 对象不可调用

'Area' object is not callable

我在 Mysql 上有数据库,在项目中我在 Flask 中使用 pony orm。我需要从索引为 1 的数据库中获取行。

这里我有在应用程序中路由的路由

routes.py

from app import app
from pony.orm import *
from app.models import Area


@app.route("/")
@app.route("/user/")
@db_session
def user():
    c = Area[1]
    return c

这里有我的数据库模型

models.py

from pony.orm import *
import config

db = Database()


class Country(db.Entity):
    id = PrimaryKey(int,auto=True)
    name = Required(str,100)
    area = Set("Area")


class Area(db.Entity):
    id = PrimaryKey(int, auto=True)
    name = Required(str, 100)
    country = Required(Country)

当我在浏览器地址中打开时 localhost:8888/ 我得到下一个错误

Traceback (most recent call last):
  File "C:\Python34\lib\site-packages\flask\app.py", line 1836, in __call__
    return self.wsgi_app(environ, start_response)
  File "C:\Python34\lib\site-packages\flask\app.py", line 1820, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "C:\Python34\lib\site-packages\flask\app.py", line 1403, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "C:\Python34\lib\site-packages\flask\_compat.py", line 33, in reraise
    raise value
  File "C:\Python34\lib\site-packages\flask\app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "C:\Python34\lib\site-packages\flask\app.py", line 1478, in full_dispatch_request
    response = self.make_response(rv)
  File "C:\Python34\lib\site-packages\flask\app.py", line 1577, in make_response
    rv = self.response_class.force_type(rv, request.environ)
  File "C:\Python34\lib\site-packages\werkzeug\wrappers.py", line 841, in force_type
    response = BaseResponse(*_run_wsgi_app(response, environ))
  File "C:\Python34\lib\site-packages\werkzeug\wrappers.py", line 57, in _run_wsgi_app
    return _run_wsgi_app(*args)
  File "C:\Python34\lib\site-packages\werkzeug\test.py", line 867, in run_wsgi_app
    app_iter = app(environ, start_response)
TypeError: 'Area' object is not callable

我什么时候出错的?

我傻了!这里的解决方案:

def user():
    c = Area[1]
    name = c.name
    return name