SlideShare a Scribd company logo
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.

More Related Content

What's hot

Makalah sistem komputer
Makalah sistem komputerMakalah sistem komputer
Makalah sistem komputerNie Andini
 
Operating system
Operating systemOperating system
Operating system
vivek anand
 
Chapter 6 output
Chapter 6   outputChapter 6   output
Chapter 6 output
haider ali
 
Operating systems basics (Graphical User Interfaces (GUIs) GUI Tools Applic...
Operating systems basics (Graphical User Interfaces (GUIs)  GUI Tools  Applic...Operating systems basics (Graphical User Interfaces (GUIs)  GUI Tools  Applic...
Operating systems basics (Graphical User Interfaces (GUIs) GUI Tools Applic...
Maryam Fida
 
Operating system 12 system programs
Operating system 12 system programsOperating system 12 system programs
Operating system 12 system programs
Vaibhav Khanna
 
Perakitan Komputer
Perakitan KomputerPerakitan Komputer
Perakitan Komputer
Wirnama Cliquer's
 
Windows Xp
Windows XpWindows Xp
Windows Xp
Andrea Bruzaca
 
Windows Registry Forensics - Artifacts
Windows Registry Forensics - Artifacts Windows Registry Forensics - Artifacts
Windows Registry Forensics - Artifacts
MD SAQUIB KHAN
 
Mobile Operating Systems
Mobile Operating SystemsMobile Operating Systems
Mobile Operating Systems
Dasun Hegoda
 
1. Introduction to Computer (CSI-321)
1. Introduction to Computer (CSI-321)1. Introduction to Computer (CSI-321)
1. Introduction to Computer (CSI-321)
ghayour abbas
 
Painel de Controle Windows XP
Painel de Controle Windows XPPainel de Controle Windows XP
Painel de Controle Windows XP
Ricardo de Moraes
 
Evolution of Microsoft windows operating systems
Evolution of Microsoft windows operating systemsEvolution of Microsoft windows operating systems
Evolution of Microsoft windows operating systems
Sai praveen Seva
 
Computer software ,
Computer software ,Computer software ,
Computer software ,Shoaib Jafri
 
Media Penyimpanan
Media PenyimpananMedia Penyimpanan
Media Penyimpanan
ShevaniaMeidika
 
Presentation on window 7
Presentation on window 7Presentation on window 7
Presentation on window 7
Muhammadusmanyar
 
Apostila informática básica
Apostila informática básicaApostila informática básica
Apostila informática básica
Jakson Silva
 
Sistema Operacional Windows Xp
Sistema Operacional Windows XpSistema Operacional Windows Xp
Sistema Operacional Windows XpSOL RIBEIRO
 
Windows 7
Windows 7Windows 7
Windows 7
Paras Wadher
 

What's hot (20)

Makalah perangkat keras
Makalah perangkat kerasMakalah perangkat keras
Makalah perangkat keras
 
Makalah sistem komputer
Makalah sistem komputerMakalah sistem komputer
Makalah sistem komputer
 
Operating system
Operating systemOperating system
Operating system
 
Chapter 6 output
Chapter 6   outputChapter 6   output
Chapter 6 output
 
Operating systems basics (Graphical User Interfaces (GUIs) GUI Tools Applic...
Operating systems basics (Graphical User Interfaces (GUIs)  GUI Tools  Applic...Operating systems basics (Graphical User Interfaces (GUIs)  GUI Tools  Applic...
Operating systems basics (Graphical User Interfaces (GUIs) GUI Tools Applic...
 
Operating system 12 system programs
Operating system 12 system programsOperating system 12 system programs
Operating system 12 system programs
 
Monitores
MonitoresMonitores
Monitores
 
Perakitan Komputer
Perakitan KomputerPerakitan Komputer
Perakitan Komputer
 
Windows Xp
Windows XpWindows Xp
Windows Xp
 
Windows Registry Forensics - Artifacts
Windows Registry Forensics - Artifacts Windows Registry Forensics - Artifacts
Windows Registry Forensics - Artifacts
 
Mobile Operating Systems
Mobile Operating SystemsMobile Operating Systems
Mobile Operating Systems
 
1. Introduction to Computer (CSI-321)
1. Introduction to Computer (CSI-321)1. Introduction to Computer (CSI-321)
1. Introduction to Computer (CSI-321)
 
Painel de Controle Windows XP
Painel de Controle Windows XPPainel de Controle Windows XP
Painel de Controle Windows XP
 
Evolution of Microsoft windows operating systems
Evolution of Microsoft windows operating systemsEvolution of Microsoft windows operating systems
Evolution of Microsoft windows operating systems
 
Computer software ,
Computer software ,Computer software ,
Computer software ,
 
Media Penyimpanan
Media PenyimpananMedia Penyimpanan
Media Penyimpanan
 
Presentation on window 7
Presentation on window 7Presentation on window 7
Presentation on window 7
 
Apostila informática básica
Apostila informática básicaApostila informática básica
Apostila informática básica
 
Sistema Operacional Windows Xp
Sistema Operacional Windows XpSistema Operacional Windows Xp
Sistema Operacional Windows Xp
 
Windows 7
Windows 7Windows 7
Windows 7
 

Viewers also liked

web2py:Web development like a boss
web2py:Web development like a bossweb2py:Web development like a boss
web2py:Web development like a boss
Francisco Ribeiro
 
Web2py Code Lab
Web2py Code LabWeb2py Code Lab
Web2py Code LabColin Su
 
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
Bruno Rocha
 
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
Gunjan Deshmukh
 
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...
Mireia Alcala
 
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
Digna González
 
Desenvolvendo mvp com python
Desenvolvendo mvp com pythonDesenvolvendo mvp com python
Desenvolvendo mvp com python
Bruno Rocha
 
Web2py
Web2pyWeb2py
Web2py
Lucas D
 
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 ...
CSUC - Consorci de Serveis Universitaris de Catalunya
 
Latex - Creación de documentos cientificos
Latex - Creación de documentos cientificosLatex - Creación de documentos cientificos
Latex - Creación de documentos cientificos
Universidad Nacional de Loja
 

Viewers also liked (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
 

Similar to Web2py tutorial to create db driven application.

Rapid Prototyping with PEAR
Rapid Prototyping with PEARRapid Prototyping with PEAR
Rapid Prototyping with PEAR
Markus Wolff
 
PofEAA and SQLAlchemy
PofEAA and SQLAlchemyPofEAA and SQLAlchemy
PofEAA and SQLAlchemyInada 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
 
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
Rob Tweed
 
Jquery dojo slides
Jquery dojo slidesJquery dojo slides
Jquery dojo slideshelenmga
 
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
Ron Reiter
 
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
Katy Slemon
 
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
Mike Subelsky
 
AngularJS Architecture
AngularJS ArchitectureAngularJS Architecture
AngularJS Architecture
Eyal Vardi
 
AngularJS Internal
AngularJS InternalAngularJS Internal
AngularJS Internal
Eyal Vardi
 
Taking Web Apps Offline
Taking Web Apps OfflineTaking Web Apps Offline
Taking Web Apps OfflinePedro Morais
 
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
Md. Aftab Uddin Kajal
 
Web internship Yii Framework
Web internship  Yii FrameworkWeb internship  Yii Framework
Web internship Yii Framework
Noveo
 
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?
Alexandru Badiu
 
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...
dotNet Miami
 
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 applicationsTim 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 UnicornsRichie Rump
 
Scalable web application architecture
Scalable web application architectureScalable web application architecture
Scalable web application architecture
postrational
 
Slickdemo
SlickdemoSlickdemo
Slickdemo
Knoldus Inc.
 
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial EnAnkur Dongre
 

Similar to 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
 

Recently uploaded

Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
Peter Spielvogel
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
RinaMondal9
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
Vlad Stirbu
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.
ViralQR
 

Recently uploaded (20)

Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.
 

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.