Flask basic python

Introduction:

Flask is a micro web framework written in python. It is well known as a lightweight framework for python web development because it is run on a stand-alone file whereas Django has multiple files for each operation such as URLs, views, and setting.

How to install flask using pip3

pip3 install flask

What you will learn from this post:what you:

  • What is flask
  • how to install flask
  • static routes in flask
  • dynamic routes in flask
  • define function in flask

How to run this file

# here I import flask library
from flask import Flask
app=Flask(__name__)



#this is stattic route ,here i set index function on my landing page
@app.route('/')
def index():
return "<h1>Hello ,this is a landing page</h1>"
#return method display this string in our landing page



#this is also static route, now i set "http://127.0.0.1:5000/about" to page function.
@app.route('/about')
def page():
return "<h1>This is about page</h1>"
# again return method display this string in our abour page



# here i used dynamic route (this type of route uses in page per user websites)
#<name> is dynamically change as per user input
#ttp://127.0.0.1:5000/user/rajat
@app.route('/user/<name>')
def users(name):
return "<h1>User name is : {}</h1>".format(name)
#here return display dynamic result with the help of string formating
if __name__=="__main__":
app.run(debug=True)
#app.run execute program and I enabled debug because this mode helps up catch errors.


 

12 thoughts on “Flask basic python

Add yours

  1. Thanks for some other informative site. Where else could I get that kind of info written in such a perfect method?
    I’ve a challenge that I am just now operating on, and I’ve been on the glance out for such info.

    Like

  2. Well, the blog is very interesting because it has many things about technology and is one of those that contain the latest trends and it is seen that they really want to make a change in the world. Thanks for sharing!!!

    Like

  3. Absolutely worth bookmarking
    for revisiting. I wonder how so much struggle you set to create this
    sort of outstanding informative website.

    Like

  4. This blog is very interesting because it has many things about technology and is one of those that contain the latest trends and it is seen that they really want to make a change in the world

    Like

  5. If you are going for most excellent contents like myself, just go to see this website all the time because it gives quality contents, thanks

    Like

Leave a comment

Create a free website or blog at WordPress.com.

Up ↑

Design a site like this with WordPress.com
Get started