Web2py

2,280 views

Published on

Slides sobre framework web2py utilizados em um mini curso no unisul techday em Tubarão, SC.

Published in: Technology, Education

Web2py

  1. 1. mini cursoweb2py@lucadavila
  2. 2. framework web python
  3. 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. 4. /models/db.py
  5. 5. #database definitiondb = DAL(sqlite://storage.sqlite)
  6. 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. 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. 8. #save changesdb.commit()#undo changesdb.rollback()
  9. 9. #countdb(Person.id > 0).count()#selectpersons = db(Person.id > 0).select()person_by_id = Person(1)
  10. 10. #update setdb(Person.id > 0).update(name="Luke")#update recordPerson(1).update_record(name="Lucas")
  11. 11. #delete setdb(Person.id > 0).delete()#delete recordPerson(1).delete_record()#truncate table (restart id sequence)Person.truncate()
  12. 12. /controllers/persons.py
  13. 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. 14. /views/persons/say_hello.html
  15. 15. #view<h1>web2py views</h1><p>Controller says: {{=some_var}}</p>
  16. 16. #url mappinghttp://hostname /app/controller/action/arg/arg2/...?var=lucas
  17. 17. #dispatching
  18. 18. downloadweb2py.com/examples/default/download
  19. 19. docsweb2py.com/examples/default/documentationweb2py.com/book
  20. 20. Obrigado!

×