Code360 powered by Coding Ninjas X Code360 powered by Coding Ninjas X
Table of contents
Web2py as Teaching Tool
Wiki Page
Frequently Asked Questions 
Do web applications work well with Python?
Describe the web2py framework.
Should one learn web2py?
How to run web2py?
Is web2py an open-source project?
Last Updated: Mar 27, 2024

How to Make a Simple Wiki Page in Web2py?

Author Kanak Rana
0 upvote
Master Python: Predicting weather forecasts
Ashwin Goyal
Product Manager @


Web2py is a free, open-source web framework that is written in Python and programmable in Python. web2py is a full-stack framework, which means it includes all of the components required to create fully functional web applications.

  • Web2py is intended to assist a web developer in adhering to good software engineering practices, such as the Model View Controller (MVC) pattern. web2py decouples data representation (the model) from data presentation (the view), as well as application logic and workflow (the controller).
  • Web2py provides libraries to assist developers in designing, implementing and testing each of these three components separately, as well as making them work together.

Although there are many web application frameworks, web2py has some standout qualities. 


Web2py as Teaching Tool

The following main reasons were the driving forces behind the creation of web2py as a teaching tool:

  • Server-side web development is simple for users to learn without sacrificing functionality. 
  • Web2py has no installation or configuration requirements, doesn't depend on anything (aside from the source code distribution, which needs Python 2.7 or 3.5+ and their standard library modules), and exposes the majority of its functionality via a Web interface, including an Integrated Development Environment with Debugger and database interface.
  • Because it uses a top-down approach to design- that is, its API was created before it was implemented—web2py has been stable from the start. 
  • Web2py has never broken backward compatibility even as new features have been added, and it won't break compatibility when new features are added in the future.
Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job

Wiki Page

Here, we create a specific wiki from scratch using only low-level APIs. The user can create, update, and search pages (by title). Additionally, the visitor can add comments, documents (as attachments to the pages), and links to such documents. We follow the Markmin syntax for our wiki syntax as a convention. An RSS feed for the sites, an XML-RPC handler, and an Ajax search page will be implemented. The actions we must take and the connections we want to make are shown in the diagram below.

Steps actions

We will start by establishing a new framework application called "Coding_Ninjas."

This is the front page for the wiki page, and the files inside it have all the source code:

first view of the page

Page, comment, and document tables must be present in the model. Both comments and the referenced document should be on the same page. A file field of the upload type, similar to the previous image application, is present in a document.

The entire model is provided below.


Page, comment, and document are the three tables that make up the model. Both comments and the referenced document should be on the same page. A file field of the upload type, just like in the previous image application, is present in a document.

db = DAL('sqlite://storage.sqlite')

From gluon. tools import *
auth = Auth(db)
crud = Crud(db)

                Field('body', 'text'),
                Field('created_on', 'datetime',,
                Field('created_by', 'reference auth_user', default=auth.user_id),

                Field('page_id', 'reference page'),
                Field('body', 'text'),
                Field('created_on', 'datetime',,
                Field('created_by', 'reference auth_user', default=auth.user_id))

                Field('page_id', 'reference page'),
                Field('file', 'upload'),
                Field('created_on', 'datetime',,
                Field('created_by', 'reference auth_user', default=auth.user_id),
                format='%(name)s') = IS_NOT_IN_DB(db, 'page.title') = IS_NOT_EMPTY() = = False = = False = IS_NOT_EMPTY() = = False = = False = = False = IS_NOT_IN_DB(db, '')
db.document.page_id.readable = db.document.page_id.writable = False
db.document.created_by.readable = db.document.created_by.writable = False
db.document.created_on.readable = db.document.created_on.writable = False
model code


The following actions were added to the controller in the controller.

Index: List of all wiki pages.

Create: A new wiki page to be added.

Show: A wiki page and any comments on it, as well as add new comments.

Edit: Modify a current page.

Document: Manage the documents that are attached to a page.

Search: Display a search box and, as the user inputs, have an Ajax callback to return any titles that match.

Callback: Ajax's callback function gives back the HTML inserted into the search results page as the user types.

def index():
""" This controller provides a dictionary, which is what the view that lists all wiki pages has produced.
 >>> index().has_key('pages')
page = db().select(,,
return dict(pages=pages)

def create():
 """ Build a new empty wiki page."""
  form = SQLFORM('index'))
  return dict(form=form)
def show():
 """ Display a wiki page"""
	this_page=, cast=int)) or redirect(URL('index')) =
	form = SQLFORM( if auth.user else None
	page comments = db( ==
	return dict(page=this_page, comments=pagecomments, form=form)

def edit():
 	""" Edit an current wiki page"""
    this_page =, cast=int)) or redirect(URL('index'))
	form = SQLFORM(, this_page).process(
	next = URL('show', args=request.args))
	return dict(form=form)
def documents():
	""" Browser, edit every file associated with that page."""

	page =, cast=int)) or redirect(URL('index'))
	db.document.page_id.default =
	grid = SQLFORM.grid(db.document.page_id ==, args=[])
	return dict(page=page, grid=grid)
	def user():
	return dict(form=auth())
def download():
	""" Allows document downloads"""

	return, db)
def search():
	""" An ajax wiki search page"""
	return dict(form=FORM(INPUT(_id='keyword',_name='keyword',_onkeyup="ajax('callback', ['keyword'], 'target');")),
def callback():
	""" An ajax callback that returns a list of links to wiki pages in the form of an <ul>."""

	query =
	pages = db(query).select(
	links = [A(p.title, _href=URL('show', for p in pages]
	return UL(*links)
def news():
	""" Creates an RSS feed from wiki pages."""
	response.generic_patterns = ['.rss']
	pages = db().select(,
	return dict(title='mywiki RSS feed',
	description='mywiki news',,
	link=URL('show',, scheme=True, host=True, extension=False),
		created_on=row.created_on) for row in pages])
	service = Service()
def find_by(keyword):
	""" For XML-RPC, finds pages that include the term."""
	return db(
def call():
	""" Exposes all logged-in services, including XML-RPC."""
return service()


Controller code


The application's view component aids in providing users with the data display. Data is pulled from the model for the data display.


{{extend 'layout.html'}}
<h1>Create new wiki page</h1>
create a new wiki page


{{extend 'layout.html'}}
<h1>Available wiki pages</h1>
[ {{=A('search', _href=URL('search'))}} ]<br />
<ul>{{for page in pages:}}
     {{=LI(A(page.title, _href=URL('show',}}
[ {{=A('create page', _href=URL('create'))}} ]

It generates the following page:


This page will show the available wiki pages that you have made earlier:

search history


{{extend 'layout.html'}}
[ {{=A('edit', _href=URL('edit', args=request.args))}} ]<br />
{{for the post in comments:}}
  <p>{{=db.auth_user[post.created_by].first_name}} on {{=post.created_on}}
     says <i>{{=post.body}}</i></p>
<h2>Post a comment</h2>


main ouptut


{{extend 'layout.html'}}
<h1>Edit wiki page</h1>
[ {{=A('show', _href=URL('show', args=request.args))}}
| {{=A('documents', _href=URL('documents', args=request.args))}} ]<br />

It creates a page that resembles the create page almost exactly.



{{extend 'layout.html'}}
<h1>Documents for page: {{=page.title}}</h1>
[ {{=A('show', _href=URL('show', args=request.args))}} ]<br />

Here you can put images that you want to add to the page(here, we have added the Coding Ninjas logo):

Document page

The logo is shown in image below:

adding coding ninjas logo


{{extend 'layout.html'}}
<h1>Search wiki pages</h1>
[ {{=A('listall', _href=URL('index'))}}]<br />
{{=form}}<br />{{=target_div}}

which creates the Ajax search form seen below:


So, this is how one can create a simple wiki page in Web2py.

Frequently Asked Questions 

Do web applications work well with Python?

Python offers various tools and frameworks, making it a strong choice for creating web applications.

Describe the web2py framework.

Web2py, written in Python and programmable in Python, is described as a free, open-source online framework for agile development that involves database-driven web applications.

Should one learn web2py?

Web2py is a top-notch framework, yes. The simplicity of usage, from installation to learning to code to distribution to deployment, is a key objective of web2py.

How to run web2py?

Web2py doesn't need to be installed. Start by running the corresponding file after unzipping the downloaded zip file for your particular operating system.

Is web2py an open-source project?

Web2py is a free, open-source web framework for developing secure database-driven web applications in an agile manner.


In this article, we have learned about how to make a simple wiki page in web2py and in which framework it runs, and model, controller, and view in detail. To know more in detail about web2py and the simple wiki page in web2py, you can take a look at the following official articles.

You can check out more articles here other than a simple wiki page in web2py:

Refer to our guided paths on Coding Ninjas Studio to learn more about DSA, Competitive Programming, JavaScript, System Design, etc. Enroll in our courses and refer to the mock test and problems available; look at the Top 150 Interview Puzzles interview experiences, and interview bundle for placement preparations.

Thank you

Do upvote our blog to help other ninjas grow. 

Happy Learning Ninja!

Next article
On Date, Datetime, and Time Format in web2py
Live masterclass