Table of contents
1.
Introduction
2.
About Web2Py
3.
About Wiki
4.
Wiki Menus
5.
Service Functions
6.
Extending the auth wiki Feature
7.
Components
8.
Frequently Asked Questions
8.1.
What is web2py used for?
8.2.
Which is better, web2py or Django?
8.3.
Should I learn web2py?
8.4.
Does web2py support Python 3?
8.5.
Is web2py a good framework?
9.
Conclusion
Last Updated: Mar 27, 2024
Easy

Wiki components to authenticate that wiki in web2py

Author Amit Singh
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

In this article, we will learn about Wiki components to authenticate that wiki in web2py.  

But before we get into that, we will learn about the Web2Py framework, which is a framework of Python Programming Language.

title

About Web2Py

Web2py can be understood as a free, open-source web framework for agile development which involves database-driven web applications; it is written in Python and programmable in Python. It is a full-stack framework consisting of all the components a developer needs to build a fully functional web application.

About Wiki

Wikis are collaborative hypertext publications that are directly maintained and edited by their own audience using web browsers. A typical wiki has numerous pages for the project's topics or scope and can either be used internally by an organisation to maintain its internal knowledge base or be available to the public.

Wiki Menus

menu

It will be assumed that a page with the slug "wiki-menu" is a description of the menu.

Let us check out an example:

- Home > @////index
- Info > @////info
- web2py > http://www.web2py.com
- - About us > @////aboutus
- - Contact us > @////contactus
You can also try this code with Online Python Compiler
Run Code

 

A menu item is on each line. For nested menu items, we deployed a double dash. The menu item title and menu item link are separated by the > symbols.

Keep in mind that the response.menu has the menu appended. No, it doesn't take its place. It automatically adds the [wiki] menu item with service features.

Service Functions

service

For instance, you might build a page with the slug "sidebar" and then embed it in your layout.html in order to use the wiki to create an editable sidebar.

{{=auth.wiki(slug='sidebar')}}
You can also try this code with Online Python Compiler
Run Code

 

Note that the word "sidebar" has no special meaning. At any point in your code, you can fetch and incorporate any wiki article. This enables you to combine standard web2py functionality with wiki functionality.

Also, keep in mind that:

auth.wiki('sidebar')
You can also try this code with Online Python Compiler
Run Code

 

Is identical to

auth.wiki(slug='sidebar')
You can also try this code with Online Python Compiler
Run Code

 

The method signature's first argument is the slug kwarg. The former has a marginally easier syntax.

Additionally, you can incorporate unique wiki features like the tag search:

{{=auth.wiki('_search')}}
You can also try this code with Online Python Compiler
Run Code

 

Or the tag cloud:

{{=auth.wiki(slug='sidebar')}}
You can also try this code with Online Python Compiler
Run Code

Extending the auth wiki Feature

yoga

When your wiki-enabled app becomes more complex, you might need to expose customized forms for wiki CRUD processes or modify the wiki database records that are maintained by the Auth interface. For instance, you could wish to add a new field validator or modify the record representation for a wiki table. Since the wiki model is only defined after the wiki interface is requested with the auth.wiki() method, this is not by default permitted. You must include the following sentence in your model file in order to permit access to the wiki-specific database setup within your app's model (i.e., db.py)

# Make sure that this is called after the auth instance is created
# and before any change to the wiki tables
auth.wiki(resolve=False)
You can also try this code with Online Python Compiler
Run Code

 

The wiki tables (i.e., wiki page) will be accessible for custom CRUD or other database actions if the line above is used in your model.

resolve=False

  • This parameter tells the auth object to merely generate the wiki model without any extra interface preparation, so keep in mind that you still need to call auth.wiki() in the controller or view to expose the wiki interface.
  • Additionally, by setting resolve to False in the method call, the wiki tables will now be used for managing wiki records using the app's default database interface at app>/appadmin.

The usual wiki tables can also be customized by including extra fields. As follows:

# Place this after auth object initialization
auth.settings.extra_fields["wiki_page"] = [Field("ablob", "blob"), ]
You can also try this code with Online Python Compiler
Run Code

 

The wiki page table gets a blob field thanks to the line above. No requirement of calling

auth.wiki(resolve=False)
You can also try this code with Online Python Compiler
Run Code

 

Unless you want access to the wiki model for further customizations.

Now, let us discuss about the Components:

Components

components

The ability to embed one action inside another action is one of the new web2py's most potent features. We refer to this as a component.

Think about the subsequent model:

db.define_table('thing', Field('name', requires=IS_NOT_EMPTY()))
You can also try this code with Online Python Compiler
Run Code

 

And now the action that is:

@auth.requires_login()
def manage_things():
    return SQLFORM.grid(db.thing)
You can also try this code with Online Python Compiler
Run Code

 

Because it returns a widget or helper rather than a dict of objects, this action is unique. This manage things action can now be added to any view, with

{{=LOAD('default', 'manage_things', ajax=True)}}
You can also try this code with Online Python Compiler
Run Code

 

As a result, the visitor can interact with the widget using Ajax without refreshing the page where the widget is hosted. All form submissions and flash messages are captured by the action, which is called via Ajax and which adopts the host page's style so that they may be processed on the current page. Additionally, the SQLFORM.grid widget restricts access by using digitally signed URLs. 

Using the MARKMIN syntax, elements similar to the one above can be included in wiki pages:

ValueError: malformed string
You can also try this code with Online Python Compiler
Run Code

 

Simply put, this instructs web2py that we wish to use the "manage things" action from the "default" controller as an Ajax "component".

Most of the users should be able to design rather complicated applications by utilizing auth.wiki to embed custom components into wiki pages and create pages and menus. We can use Wikis as a tool to let group members produce pages, but they can also be used to design applications in a modular approach.

Frequently Asked Questions

What is web2py used for?

Python dynamic web content programming is made possible via Web2py. Web2py is made to make laborious web development jobs more accessible, such as creating web forms from scratch, while a web developer can still do it if necessary.

Which is better, web2py or Django?

Due to its smaller size, short learning curve, and lack of project-level configuration files, web2py differs from Django. Compared to PHP-based frameworks and Java-based frameworks, web2py is far less verbose and has a lot clearer syntax. This makes applications easier to comprehend, maintain, and create.

Should I learn web2py?

More than web-development purposes, web2py is primarily used as a teaching tool. Because of its graphical interface and built-in web IDE, it makes it easy for the developer to learn server-side web development.

Does web2py support Python 3?

web2py actually runs with CPython (the C implementation) and PyPy (Python written in Python) on Python 2.7 and Python 3.

Is web2py a good framework?

To summarize, Web2py is a free, fast, secure web development framework that is entirely written in python and encourages using python in every way possible (model, view, controller). It is an excellent framework for small web applications or prototypes but fails to fulfill the enterprise-class quality requirements.

Conclusion

In this article, we learned Wiki components to authenticate that wiki in web2py. After reading about Wiki components to authenticate that wiki in web2py , are you not feeling excited to read/explore more articles on the topic of Web2Py? Don't worry; Coding Ninjas has you covered. 

To learn, see Markmin basics and oembed Protocol in web2py and sqlform and insertupdatedelete in web2py.

Refer to our Guided Path on Coding Ninjas Studio to upskill yourself in Data Structures and AlgorithmsCompetitive ProgrammingJavaScriptSystem Design, and many more! If you want to test your competency in coding, you may check out the mock test series and participate in the contests hosted on Coding Ninjas Studio! But if you have just started your learning process and are looking for questions asked by tech giants like Amazon, Microsoft, Uber, etc., you must look at the problemsinterview experiences, and interview bundle for placement preparations.

Nevertheless, you may consider our paid courses to give your career an edge over others!

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

Merry Learning

Live masterclass