Movatterモバイル変換


[0]ホーム

URL:


Open In App

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.

Installation:

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

Createaflask app:

3) Create a file and name it as app.py

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  -app.py

Python3
# import necessary librariesfromflaskimportFlask,request,render_templateimportwikipediaapp=Flask(__name__)# create HOME View@app.route("/",methods=["POST","GET"])defhome():ifrequest.method=="GET":returnrender_template("index.html")else:search=request.form["search"]# Fetch data from wikipediaresult=wikipedia.summary(search,sentences=2)returnf"<h1>{result}</h1>"if__name__=='__main__':app.run(debug=True)

Create a fileindex.html that will be used by flask - 

HTML
<!DOCTYPE html><html><head><title>Wikipedia Search</title></head><body><formmethod="post"><inputtype="text"name="search"><br><buttontype="submit">Search</button></form></body></html>

Output:

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


Explore

Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences

[8]ページ先頭

©2009-2025 Movatter.jp