Web2py

All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.
 75 views
of 20

Please download to get full document.

View again

Description
1. mini cursoweb2py@lucadavila 2. framework web python 3. # opensource# seguro# model view controller# windows, mac, unix/linux, GAE# SQLite, PostgreSQL, MySQL, Oracle,…
Share
Transcript
  • 1. mini cursoweb2py@lucadavila
  • 2. framework web python
  • 3. # opensource# seguro# model view controller# windows, mac, unix/linux, GAE# SQLite, PostgreSQL, MySQL, Oracle, GAE...# apache, lighttpd, cherokee, *mod_python ...# compatibilidade reversa# curva aprendizado pequena# interface administrativa web
  • 4. /models/db.py
  • 5. #database definitiondb = DAL(sqlite://storage.sqlite)
  • 6. #model definitionPerson = db.define_table(persons, Field(name, label=Your name), Field(email),)#validatorsPerson.name.requires = IS_NOT_EMPTY()Person.email.requires = IS_EMPTY_OR(IS_EMAIL())
  • 7. #insert (without validating)Person.insert(name="Lucas DAvila", email="lucassdvl@gmail.com")Person.insert(name="", email="foo")#validate and insertPerson.validate_and_insert(name="", email="foo")<Row {errors: <Row {name: <lazyT enter a value>,email: <lazyT enter a valid email address>}>, id: None}>
  • 8. #save changesdb.commit()#undo changesdb.rollback()
  • 9. #countdb(Person.id > 0).count()#selectpersons = db(Person.id > 0).select()person_by_id = Person(1)
  • 10. #update setdb(Person.id > 0).update(name="Luke")#update recordPerson(1).update_record(name="Lucas")
  • 11. #delete setdb(Person.id > 0).delete()#delete recordPerson(1).delete_record()#truncate table (restart id sequence)Person.truncate()
  • 12. /controllers/persons.py
  • 13. #action returning a stringdef say_hello(): return dict(some_var = "Hello world!")#action returning a set of database recordsdef persons() : persons = db(Person.id > 0).select() return locals()
  • 14. /views/persons/say_hello.html
  • 15. #view<h1>web2py views</h1><p>Controller says: {{=some_var}}</p>
  • 16. #url mappinghttp://hostname /app/controller/action/arg/arg2/...?var=lucas
  • 17. #dispatching
  • 18. downloadweb2py.com/examples/default/download
  • 19. docsweb2py.com/examples/default/documentationweb2py.com/book
  • 20. Obrigado!
  • We Need Your Support
    Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

    Thanks to everyone for your continued support.

    No, Thanks