我制作了一个脚本( dbcreation.py ),用bottle-peewee-plugin创建了一个数据库:
import os, sys
from bottle import Bottle
from bottle_peewee import PeeweePlugin
from peewee import Model, ForeignKeyField, CharField, TextField, IntegerField, BooleanField, DateTimeField, DateField, TimeField
import datetime
app = Bottle()
db = PeeweePlugin('sqlite:///x.db')
class BaseModel(Model):
class Meta:
database = db.proxy
class Roomtype(BaseModel):
roomtype_de = CharField(max_length=80)
hint_de = CharField(max_length=250)
app.install(db)
db.database.create_tables([Roomtype])
roomtypes = [
{'roomtype_de': 'bla'},
{'roomtype_de': 'bla'},
]
with db.database.atomic():
Roomtype.insert_many(roomtypes).execute()
和另一个包含我的bootle-app的脚本( app.py ):
from bottle import Bottle, route, get, post, request, run, template
from bottle_peewee import PeeweePlugin
from peewee import Model, ForeignKeyField, CharField, TextField, IntegerField, BooleanField, DateTimeField, DateField, TimeField
app = Bottle()
db = PeeweePlugin('sqlite:///x.db')
@route('/my_function')
def my_function():
return db.database.Roomtype.get(Roomtype.id == 1).roomtype_de
app.install(db)
我无法在数据库中选择任何条目并接收以下追溯:
return db.database.Roomtype.get(Roomtype.id == 1).roomtype_de
AttributeError: 'SqliteDatabase' object has no attribute 'Roomtype'
我错过了什么?
答案 0 :(得分:0)
可能会将其更改为:
db.Roomtype.get(...)
我很困惑为什么你在某些地方使用db.Roomtype
而在其他地方只使用普通的Roomtype
。