Open In App

Wikipedia search app using Flask Framework – Python

Last Updated : 26 May, 2022
Like Article

Flask is a micro web framework written in Python. It is classified as a micro-framework because it does not require particular tools or libraries. Flask is a lightweight WSGI web application framework. It is designed to make getting started quick and easy, with the ability to scale up to complex applications. Wikipedia is a Python library that makes it easy to access and parse data from


1) In order to create the flask app we have to first install the flask.

pip install flask

2) In order to extract the data from Wikipedia, we must first install the Python Wikipedia library.

pip install wikipedia

Create a flask app:

3) Create a file and name it as

4) Create the templates folder to store all the html files.

Folder structure:

How to create wikipedia search app using Flask Framework?

Now, let’s start coding the application

Create the file  –


# import necessary libraries
from flask import Flask, request, render_template
import wikipedia
app = Flask(__name__)
# create HOME View
@app.route("/", methods=["POST", "GET"])
def home():
    if request.method == "GET":
        return render_template("index.html")
        search = request.form["search"]
        # Fetch data from wikipedia
        result = wikipedia.summary(search, sentences=2)
        return f"<h1>{result}</h1>"
if __name__ == '__main__':

Create a file index.html that will be used by flask – 


<!DOCTYPE html>
    <title>Wikipedia Search</title>
    <form method="post">
    <input type="text" name="search">
    <button type="submit">Search</button>


If we search INDIA in this input tag then the output is:

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads