0

I'm following this example to try and implement a way of uploading images from the default page of my application in web2py into the database. I went through the whole thing and can now view the images on the default page that were uploaded through the appadmin controller and the function /insert/db/image

What I would like is to have a small section on the default page to upload images from rather than having to go to a different page in /appadmin/insert/db/image

How would I implement this in the default controller and view? Thank you

Raul M
  • 124
  • 6

1 Answers1

0

You could simply add a SQLFORM to the index page:

def index():
    [your existing code]
    form = SQLFORM(db.image).process()
    return dict(..., form=form)

In /views/default/index.html, wherever you want the form, add:

{{=form}}

Alternatively, you can use a grid, which provides an entire interface for listing, creating, and editing database records. You would replace the form lines above with:

grid = SQLFORM.grid(db.image)
return dict(..., grid=grid)

and:

{{=grid}}

Note, by default, all grid URLs are signed, so to create/edit/delete records, the user must be logged in (to disable this protection, set user_signature=False).

This is all covered in the forms chapter.

Anthony
  • 25,466
  • 3
  • 28
  • 57