₹2,000.00 ₹1,500.00
The Python Programming Language at Champak's World
  • 15 students
  • 22 lessons
  • 0 quizzes
  • 10 week duration


Running a Web Server using Python in Spyder

This is one of the more important lessons in Python. In this lesson we shall learn how to create and run a Web Server using Python on Spyder. In addition we will implement REST API for insert, update, delete and search.

To begin with let us create a server.

Flask is a Python web framework for developing web applications. There is another famous web framework for Python namely DJango. Flask is lightweight as compared to DJango and therefore we will start with Flask

To create a server you begin by importing Flask into your Python program. Then you create an app.

from flask import Flask
app = Flask(__name__)


def index():
return "Welcome to Python Server""localhost", port=int("777"))

We are importing  Flask in the first line
from flask import Flask
The second line creates the app by calling its constructor.
app = Flask(__name__)

__name__ is the name of the current module and will be __main__
You can actually check this by writing

in a program.

@app.route(“/”,) defines the default web path and then we have  a return statement

return “Welcome to Python Server”

This will show up in the browser.
Finally we use to run the application. will run the server on the default port =5000.”localhost”, port=int(“80”))

Check up the console and get the portno.

runfile(‘C:/Users/Champak Roy/’, wdir=’C:/Users/Champak Roy’)
* Running on (Press CTRL+C to quit) – – [02/May/2019 12:59:57] “GET / HTTP/1.1” 200 – – – [02/May/2019 12:59:57] “GET /favicon.ico HTTP/1.1” 404 –

Run the given code and open the url in the browser.



Finally we have a complete code for insert, delete update and search as promised earlier.

from flask import Flask
app = Flask(__name__)

def search(cityname):

result=d1.get(int(cityname),"Not Found")
return result


def insert(citynumber,cityname):

return "Inserted"


def index():

return "Welcome to Python Server"


def update(citynumber,cityname):

return "Updated"


def delete(citynumber):

del( d1[int(citynumber)])
return "Deleted"
return "Not Found"
if __name__ == "__main__":
#print(__name__)"localhost", port=int("777"))

Let us analyze the Insert function


def insert(citynumber,cityname):

return “Inserted”

The route starts with insert and contains two parameters citynumber and cityname. The cityname will be inserted with the key citynumber.


The output shows Inserted.

Try out the other URLs. That is an assignment.


Leave a Reply

Your email address will not be published. Required fields are marked *