The problem is that you are not saving your model (the table
definitions) and web2py starts from scratch on every request, so your
table is being created in the DB but web2py does not know about it.
That is what models do, they define the tables that are visible in
web2py.

Save that db.define_table... code in a file under the models folder,
then web2py will pick it up on all subsequent requests.


On May 24, 8:39 pm, Ialejandro <[email protected]> wrote:
> Hi everyone, I'm trying to make an app where a user can create its own
> tables bases in some attributes, I have this:
>
> View:
>
> {{extend 'layout.html'}}
>
> <form enctype="multipart/form-data"
>       action="{{=URL()}}" method="post">
> Project Name:
> <input name="projname" />
> <br />Number Of Fields:
> <input name="numfields" />
> <br />Name of Fields:
> <input name="namfields" />
> <br /><input type="submit" />
> </form>
> <h2>Submitted variables</h2>
> {{=BEAUTIFY(request.vars)}}
>
> Controller:
>
> def config():
>
>     if request.vars:
>         proj_name = session.projname = request.vars.projname
>         num_fields= session.numfields= request.vars.numfields
>         nam_fields= session.namfields= request.vars.namfields
>
>         tblname = proj_name + "_custom"
>         response.flash = tblname
>
>         createtable(tblname)
>
>     return dict()
>
> And in utils.py (inside models folder)
>
> def createtable(tablename):
>     tbl = db.define_table(tablename,Field('a'))
>
> But it doesn't work :(
> The form works, I can get the variables by request.vars, but the table
> is not created, how could I create dynamic tables??
> If an user needs a table called "project1" with 2 fields "F1 and F2"
> and another user needs more different fields and table name, how could
> I make this??
>
> Thanks!

Reply via email to