Table of contents
1.
Introduction
2.
Settings
3.
Frequently Asked Questions
3.1.
What is the web2py Framework?
3.2.
Is web2py better than Django?
3.3.
What is a Python flask app?
3.4.
Is web2py an MVC framework?
4.
Conclusion
Last Updated: Mar 27, 2024
Medium

Settings of CRUD in web2py

Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

Hello Ninjas,

As Robert Frost said: "Two roads diverged in a wood, and I – I took the one less traveled by, and that has made all the difference." 

robert frost quote

You are thinking that is why I am talking about it. So the reason is that today we will cover unique topics i,e., Settings of CRUD in web2py. 

If you search on the web about Settings of CRUD in web2py, you don't find much more about the Settings of CRUD in web2py as Settings of CRUD in web2py is itself a unique topic and so today will cover this topic.

But the first question comes to our mind is that what web2py is.

python

web2py is an open-source web application written in the python programming language. web2py allows web developers to program dynamic web content using python. It helps users by reducing tedious web development tasks, such as developing web forms from scratch, although a web developer may build a form from scratch if required. It is a full-stack framework consisting of all the components a developer needs to build fully functional web applications. web2py provides various functionalities like creating, modifying, deploying, and managing an application from anywhere using your browser.


The CRUD means Create/Read/Update/Delete, which is an API that is an experimental interface on top of SQLFORM. 

createreadupdatedelete

CRUD creates an SQLFORM and incorporates the creation, processing of the form, the notification, and the redirection, all in one function.

Settings

Let's discuss the setting of the CRUD attributes and their values with their meaning.

settings

Followings are the list of the CRUD attributes-


To enforce authentication on all crud forms:

crud.settings.auth = auth
You can also try this code with Online Python Compiler
Run Code

 

Attributes to specify the controller that defines the data function which returns the crud object:

crud.settings.controller = 'default'
You can also try this code with Online Python Compiler
Run Code

 

Attributes to specify the URL to redirect to after a successful "update" record:

crud.settings.update_next = URL('index')
You can also try this code with Online Python Compiler
Run Code

 

Attributes to specify the URL to redirect to after a successful "create" record:

crud.settings.create_next = URL('index')
You can also try this code with Online Python Compiler
Run Code

 

Attributes to specify the URL to redirect to after a successful "delete" record:

crud.settings.delete_next = URL('index')
You can also try this code with Online Python Compiler
Run Code

 

Attributes to specify the URL to be used for linking uploaded files:

crud.settings.download_url = URL('download')
You can also try this code with Online Python Compiler
Run Code

 

download

Attributes to specify extra functions to be executed after standard validation procedures for crud.create forms:

crud.settings.create_onvalidation = StorageList()
You can also try this code with Online Python Compiler
Run Code

 

Here, StorageList is the same as a Storage object. They are both defined in the file "gluon/storage.py," but it defaults to [] as opposed to None. It allows the following syntax:

crud.settings.create_onvalidation.mytablename.append(lambda form: ...)
You can also try this code with Online Python Compiler
Run Code

 

Attributes to specify extra functions to be executed after completion of crud.create forms:

crud.settings.create_onaccept = StorageList()
You can also try this code with Online Python Compiler
Run Code

 

Attributes to specify extra functions to be executed after standard validation procedures for crud.update forms:

crud.settings.update_onvalidation = StorageList()
You can also try this code with Online Python Compiler
Run Code

 

Attributes to specify extra functions to be executed after completion of crud.update if record is deleted:

crud.settings.update_ondelete = StorageList()
You can also try this code with Online Python Compiler
Run Code

 

Attributes to specify extra functions to be executed after completion of crud.update forms:

crud.settings.update_onaccept = StorageList()
You can also try this code with Online Python Compiler
Run Code

 

Attributes to specify extra functions to be executed after completion of crud.delete:

crud.settings.delete_onaccept = StorageList()
You can also try this code with Online Python Compiler
Run Code

 

Attributes to determine whether the "update" forms should have a "delete" button:

crud.settings.update_deletable = True
You can also try this code with Online Python Compiler
Run Code

 

Attributes to determine whether the "update" forms should show the id of the edited record:

crud.settings.showid = False
You can also try this code with Online Python Compiler
Run Code

 

Attributes to determine whether forms should keep the previously inserted values or reset to default after successful submission is

crud.settings.keepvalues = False
You can also try this code with Online Python Compiler
Run Code

 

Crud always detects whether a record being edited has been modified by a third party in the time between when the form is displayed and when it is submitted. This behavior is equivalent to

form.process(detect_record_change=True)
You can also try this code with Online Python Compiler
Run Code

 

and it is set in:

crud.settings.detect_record_change = True
You can also try this code with Online Python Compiler
Run Code

 

It can be changed/disabled by setting the variable to False.

We can change the form style by

crud.settings.formstyle = 'table3cols' or 'table2cols' or 'divs' or 'ul'
You can also try this code with Online Python Compiler
Run Code

 

You can set the separator in all crud forms:

crud.settings.label_separator = ':'
You can also try this code with Online Python Compiler
Run Code

 

Frequently Asked Questions

What is the web2py Framework?

web2py is a free and open-source web framework used for agile development which involves database-driven web applications and is written in Python.

Is web2py better than Django?

web2py differs from Django because it is more compact, easier to learn, and has no project-level configuration files. Its syntax is much cleaner than the PHP-based frameworks.

What is a Python flask app?

Flask is a small and lightweight Python web framework that provides valuable tools and features that make creating web applications in Python easier.

Is web2py an MVC framework?

The design of web2py was inspired by the Ruby on Rails and Django frameworks. Like these frameworks, web2py focuses on rapid development, favors convention over the configuration approach, and follows a model–view–controller (MVC) architectural pattern.

Conclusion

We have discussed a unique topic, Setting of CRUD in web2py, in which we cover several issues such as what web2py is, Settings of CRUD attributes, and some FAQs.

After reading about the settings of CRUD in web2py, are you not feeling excited to read/explore more articles on Data Structures and Algorithms? Don't worry; Coding Ninjas has you covered. See web2pyWhat is web2pyweb2py Introductionweb2py Installation, and Creating a New Web2Py Application to learn.

Do upvote our blogs if you find them helpful and engaging!

Happy Learning!

Live masterclass