I have database on Mysql and in project I use pony orm in Flask. I need to get row from database with index 1.
Here I have routes for routing in app
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
Here I have models for my database
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)
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
When I made error?
I'm stupid! Here solution:
def user():
c = Area[1]
name = c.name
return name