SlideShare uma empresa Scribd logo
1 de 14
Baixar para ler offline
Web2py Tutorial

    This presentation is a summary of the
 documentation to create a simple database
 driven application using the web2py python
framework. The documentation can be found
                     here.
Download and Run




Download the framework from here. Go to the
directory where you downloaded the
application, and run python web2py.py.
Choose an Admin Password.
Login to the Admin Interface
Create an Application
Database Modeling
Database Model Implementation

''' We create a table notes, with the columns title, description, author,
subject and a publication date. We also mention that the fields title, description,
author are required, and that the publication date will be automatically assigned the current time.'''

db.define_table('notes',
          Field('title', length=200, required=True, requires=IS_NOT_EMPTY()),
          Field('description', length=2000, required=True, requires=IS_NOT_EMPTY()),
          Field('author', db.auth_user, required=True, requires=IS_NOT_EMPTY()),
          Field('subject', length=20,requires=IS_IN_SET(('english', 'philosophy', 'metaphysics'))),
          Field('pub_date', 'datetime', default=request.now, writable=False)
          )
We need functions that handle the
request from user.
Function Definition to handle CRUD
operations. (index)
def index():

  ''' Makes a db query to select all the notes,
  orders the notes by the publication date and
  returns a dictionary to the template, containing
  all the notes.'''

  response.flash = "Welcome to the index view!"
  notes = db(db.notes).select(orderby=db.notes.pub_date)
  return dict(notes=notes)
Function Definition contd.. (create)
def create():

  ''' Generates a form corresponding to the model and
      renders it, if the form sends some data, the function
      validates the data and saves the data in the database.'''

  response.flash = "This is the create page"
  form=SQLFORM(db.notes)
  if form.process().accepted:
     response.flash = 'form accepted'
  elif form.errors:
     response.flash = 'form has errors'
  else:
      response.flash = 'please fill the form'
  return dict(form=form)
Function Definitions contd.. (edit)
def edit():


  ''' The function pre-populates the data from the note instance
     that has been requested to be edited and renders it,
     once client sends in some data, it saves it in the database.'''


  note = db.notes(request.args(0)) or redirect(URL('error'))
  form=SQLFORM(db.notes, note, deletable = True)
  if form.validate():
     if form.deleted:
          db(db.notes.id==note.id).delete()
          redirect(URL('index'))
     else:
          note.update_record(**dict(form.vars))
          response.flash = 'records changed'
  else:
     response.flash = 'Something went wrong!'
  return dict(form=form)
We need to create HTML templates
2 basic templates would do the job!
The previous slide shows how to create a
template. We need to create a template to
show all the content (index.html) and a
template to create/edit the content(create.html)

The files can be found here.
Its Done!!
Its time to reap the fruits of the hard work
web2py just did for us :)

The source code is available here.

You can share it if you liked it, in case of doubts
send a mail to: contact@fruiapps.com.

Mais conteúdo relacionado

Mais procurados

1_Introduction to Artificial Intelligence.pdf
1_Introduction to Artificial Intelligence.pdf1_Introduction to Artificial Intelligence.pdf
1_Introduction to Artificial Intelligence.pdf
asxc1
 

Mais procurados (10)

Eyeos
EyeosEyeos
Eyeos
 
Java project-presentation
Java project-presentationJava project-presentation
Java project-presentation
 
Ikigai
IkigaiIkigai
Ikigai
 
My Ikigai Illustration.pptx
My Ikigai Illustration.pptxMy Ikigai Illustration.pptx
My Ikigai Illustration.pptx
 
Intro to GraphQL for Database Developers
Intro to GraphQL for Database DevelopersIntro to GraphQL for Database Developers
Intro to GraphQL for Database Developers
 
Creating Web Applications with IDMS, COBOL and ADSO
Creating Web Applications with IDMS, COBOL and ADSOCreating Web Applications with IDMS, COBOL and ADSO
Creating Web Applications with IDMS, COBOL and ADSO
 
Morning Habits of Successful People
Morning Habits of Successful PeopleMorning Habits of Successful People
Morning Habits of Successful People
 
UiPath Test Suite の魅力とは?-続編-
UiPath Test Suite の魅力とは?-続編-UiPath Test Suite の魅力とは?-続編-
UiPath Test Suite の魅力とは?-続編-
 
1_Introduction to Artificial Intelligence.pdf
1_Introduction to Artificial Intelligence.pdf1_Introduction to Artificial Intelligence.pdf
1_Introduction to Artificial Intelligence.pdf
 
Using Release(deallocate) and Painful Lessons to be learned on DB2 locking
Using Release(deallocate) and Painful Lessons to be learned on DB2 lockingUsing Release(deallocate) and Painful Lessons to be learned on DB2 locking
Using Release(deallocate) and Painful Lessons to be learned on DB2 locking
 

Destaque

Web2py Code Lab
Web2py Code LabWeb2py Code Lab
Web2py Code Lab
Colin Su
 

Destaque (11)

web2py:Web development like a boss
web2py:Web development like a bossweb2py:Web development like a boss
web2py:Web development like a boss
 
Web2py Code Lab
Web2py Code LabWeb2py Code Lab
Web2py Code Lab
 
Using web2py's DAL in other projects or frameworks
Using web2py's DAL in other projects or frameworksUsing web2py's DAL in other projects or frameworks
Using web2py's DAL in other projects or frameworks
 
Mule esb – connecting to ms sql db
Mule esb – connecting to ms sql dbMule esb – connecting to ms sql db
Mule esb – connecting to ms sql db
 
Plantillas para la creación de material docente accesible con herramientas of...
Plantillas para la creación de material docente accesible con herramientas of...Plantillas para la creación de material docente accesible con herramientas of...
Plantillas para la creación de material docente accesible con herramientas of...
 
LaTeX sin dolor.
LaTeX sin dolor.LaTeX sin dolor.
LaTeX sin dolor.
 
5-Beamer: Creación de presentaciones con LaTeX
5-Beamer: Creación de presentaciones con LaTeX5-Beamer: Creación de presentaciones con LaTeX
5-Beamer: Creación de presentaciones con LaTeX
 
Desenvolvendo mvp com python
Desenvolvendo mvp com pythonDesenvolvendo mvp com python
Desenvolvendo mvp com python
 
Web2py
Web2pyWeb2py
Web2py
 
Gestión de datos de investigación: trabajo cooperativo en las bibliotecas de ...
Gestión de datos de investigación: trabajo cooperativo en las bibliotecas de ...Gestión de datos de investigación: trabajo cooperativo en las bibliotecas de ...
Gestión de datos de investigación: trabajo cooperativo en las bibliotecas de ...
 
Latex - Creación de documentos cientificos
Latex - Creación de documentos cientificosLatex - Creación de documentos cientificos
Latex - Creación de documentos cientificos
 

Semelhante a Web2py tutorial to create db driven application.

PofEAA and SQLAlchemy
PofEAA and SQLAlchemyPofEAA and SQLAlchemy
PofEAA and SQLAlchemy
Inada Naoki
 
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
SPTechCon
 
Jquery dojo slides
Jquery dojo slidesJquery dojo slides
Jquery dojo slides
helenmga
 
Taking Web Apps Offline
Taking Web Apps OfflineTaking Web Apps Offline
Taking Web Apps Offline
Pedro Morais
 
Tips and tricks for building api heavy ruby on rails applications
Tips and tricks for building api heavy ruby on rails applicationsTips and tricks for building api heavy ruby on rails applications
Tips and tricks for building api heavy ruby on rails applications
Tim Cull
 
Entity Framework: Code First and Magic Unicorns
Entity Framework: Code First and Magic UnicornsEntity Framework: Code First and Magic Unicorns
Entity Framework: Code First and Magic Unicorns
Richie Rump
 
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial En
Ankur Dongre
 

Semelhante a Web2py tutorial to create db driven application. (20)

Rapid Prototyping with PEAR
Rapid Prototyping with PEARRapid Prototyping with PEAR
Rapid Prototyping with PEAR
 
PofEAA and SQLAlchemy
PofEAA and SQLAlchemyPofEAA and SQLAlchemy
PofEAA and SQLAlchemy
 
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
 
Developing node-mdb: a Node.js - based clone of SimpleDB
Developing node-mdb: a Node.js - based clone of SimpleDBDeveloping node-mdb: a Node.js - based clone of SimpleDB
Developing node-mdb: a Node.js - based clone of SimpleDB
 
Jquery dojo slides
Jquery dojo slidesJquery dojo slides
Jquery dojo slides
 
Writing HTML5 Web Apps using Backbone.js and GAE
Writing HTML5 Web Apps using Backbone.js and GAEWriting HTML5 Web Apps using Backbone.js and GAE
Writing HTML5 Web Apps using Backbone.js and GAE
 
Laravel 8 export data as excel file with example
Laravel 8 export data as excel file with exampleLaravel 8 export data as excel file with example
Laravel 8 export data as excel file with example
 
SproutCore and the Future of Web Apps
SproutCore and the Future of Web AppsSproutCore and the Future of Web Apps
SproutCore and the Future of Web Apps
 
AngularJS Architecture
AngularJS ArchitectureAngularJS Architecture
AngularJS Architecture
 
AngularJS Internal
AngularJS InternalAngularJS Internal
AngularJS Internal
 
Taking Web Apps Offline
Taking Web Apps OfflineTaking Web Apps Offline
Taking Web Apps Offline
 
ASP.NET Core MVC with EF Core code first
ASP.NET Core MVC with EF Core code firstASP.NET Core MVC with EF Core code first
ASP.NET Core MVC with EF Core code first
 
Web internship Yii Framework
Web internship  Yii FrameworkWeb internship  Yii Framework
Web internship Yii Framework
 
What's new in the Drupal 7 API?
What's new in the Drupal 7 API?What's new in the Drupal 7 API?
What's new in the Drupal 7 API?
 
dotNet Miami - June 21, 2012: Richie Rump: Entity Framework: Code First and M...
dotNet Miami - June 21, 2012: Richie Rump: Entity Framework: Code First and M...dotNet Miami - June 21, 2012: Richie Rump: Entity Framework: Code First and M...
dotNet Miami - June 21, 2012: Richie Rump: Entity Framework: Code First and M...
 
Tips and tricks for building api heavy ruby on rails applications
Tips and tricks for building api heavy ruby on rails applicationsTips and tricks for building api heavy ruby on rails applications
Tips and tricks for building api heavy ruby on rails applications
 
Entity Framework: Code First and Magic Unicorns
Entity Framework: Code First and Magic UnicornsEntity Framework: Code First and Magic Unicorns
Entity Framework: Code First and Magic Unicorns
 
Scalable web application architecture
Scalable web application architectureScalable web application architecture
Scalable web application architecture
 
Slickdemo
SlickdemoSlickdemo
Slickdemo
 
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial En
 

Último

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Último (20)

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 

Web2py tutorial to create db driven application.

  • 1. Web2py Tutorial This presentation is a summary of the documentation to create a simple database driven application using the web2py python framework. The documentation can be found here.
  • 2. Download and Run Download the framework from here. Go to the directory where you downloaded the application, and run python web2py.py.
  • 3. Choose an Admin Password.
  • 4. Login to the Admin Interface
  • 7. Database Model Implementation ''' We create a table notes, with the columns title, description, author, subject and a publication date. We also mention that the fields title, description, author are required, and that the publication date will be automatically assigned the current time.''' db.define_table('notes', Field('title', length=200, required=True, requires=IS_NOT_EMPTY()), Field('description', length=2000, required=True, requires=IS_NOT_EMPTY()), Field('author', db.auth_user, required=True, requires=IS_NOT_EMPTY()), Field('subject', length=20,requires=IS_IN_SET(('english', 'philosophy', 'metaphysics'))), Field('pub_date', 'datetime', default=request.now, writable=False) )
  • 8. We need functions that handle the request from user.
  • 9. Function Definition to handle CRUD operations. (index) def index(): ''' Makes a db query to select all the notes, orders the notes by the publication date and returns a dictionary to the template, containing all the notes.''' response.flash = "Welcome to the index view!" notes = db(db.notes).select(orderby=db.notes.pub_date) return dict(notes=notes)
  • 10. Function Definition contd.. (create) def create(): ''' Generates a form corresponding to the model and renders it, if the form sends some data, the function validates the data and saves the data in the database.''' response.flash = "This is the create page" form=SQLFORM(db.notes) if form.process().accepted: response.flash = 'form accepted' elif form.errors: response.flash = 'form has errors' else: response.flash = 'please fill the form' return dict(form=form)
  • 11. Function Definitions contd.. (edit) def edit(): ''' The function pre-populates the data from the note instance that has been requested to be edited and renders it, once client sends in some data, it saves it in the database.''' note = db.notes(request.args(0)) or redirect(URL('error')) form=SQLFORM(db.notes, note, deletable = True) if form.validate(): if form.deleted: db(db.notes.id==note.id).delete() redirect(URL('index')) else: note.update_record(**dict(form.vars)) response.flash = 'records changed' else: response.flash = 'Something went wrong!' return dict(form=form)
  • 12. We need to create HTML templates
  • 13. 2 basic templates would do the job! The previous slide shows how to create a template. We need to create a template to show all the content (index.html) and a template to create/edit the content(create.html) The files can be found here.
  • 14. Its Done!! Its time to reap the fruits of the hard work web2py just did for us :) The source code is available here. You can share it if you liked it, in case of doubts send a mail to: contact@fruiapps.com.