First Flask application



First Flask application

  • We will build our first python website built using the Flask framework. To Write the following code and save to a file named as script.py.

Sample code

from flask import Flask  
  
app = Flask(__name__) #creating the Flask class object   
 
@app.route('/') #decorator drfines the   
def home():  
    return "Hello, welcome to wikitechy";  
  
if __name__ =='__main__':  
 app.run(debug = True)  
  • To run this python code on the command line and To check the result.

Output

Serving Flask app "script" (lazy loading)
Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
Debug mode: on
Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
Restarting with stat
Debugger is active!
Debugger PIN: 334-809-386
  • It is to be run to on the browser.
 Output

Output

  • To build our python web application, we used to import the Flask module.
  • route() function - The Flask class defines the URL mapping of the associated function.

Syntax

app.route(rule, options)
 Approute

Approute

  • Rule - Represents the list of parameters to be associated with the rule object.
  • Options - Represents the URL binding with the function.

The run method of the Flask class is used to run the flask application on the local development Server.

Syntax

app.run(host, port, debug, options)
 Run

Run Method

  • Host - The default hostname is 127.0.0.1.
  • Port - The port number to which the server is listening to. The default port number is 5000.
  • Debug - The default is false. It provides debug information if it is set to true.
  • Options - It contains the information to be forwarded to the server.

If you want to learn about Python Course , you can refer the following links Python Training in Chennai , Machine Learning Training in Chennai , Data Science Training in Chennai , Artificial Intelligence Training in Chennai



Related Searches to First Flask application