黄祥
unread,Mar 10, 2022, 8:48:38 AM3/10/22Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to web2py-users
controlelrs/test.py
from peewee import *
db = SqliteDatabase('peewee.sqlite')
class BaseModel(Model):
class Meta:
database = db
class Person(BaseModel):
name = CharField()
def peewee_create_tables():
with db:
db.create_tables([Person] )
def peewee_get():
table_name = request.args(0)
peewee_create_tables()
all_columns = Person.select()
all_columns_output = [e for e in all_columns.tuples() ]
return str(all_columns_output)
objective
can pass the table name from curl terminal cli into request.args(0)
e.g.
all_columns = table_name.select()
result
Traceback (most recent call last):
File "/Users/sugizo/Downloads/web2py/gluon/restricted.py", line 219, in restricted
exec(ccode, environment)
File "/Users/sugizo/Downloads/web2py/applications/test/controllers/test.py", line 95, in <module>
File "/Users/sugizo/Downloads/web2py/gluon/globals.py", line 430, in <lambda>
self._caller = lambda f: f()
File "/Users/sugizo/Downloads/web2py/applications/test/controllers/test.py", line 47, in peewee_get
all_columns = table_name.select()
AttributeError: 'str' object has no attribute 'select'
question
how to pass the request.args(0) into class <class 'peewee.ModelBase'> using web2py way ?
thanks and best regards,
stifan