Skip to content

A complete beginner friendly Python Flask tutorial 🐍. Learn from basic template rendering to deploying in web servers.

License

Notifications You must be signed in to change notification settings

poojahukkire/flask-tutorial

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A complete Flask tutorial for beginners

Flask is an API of Python that allows us to build up web-applications. It was developed by Armin Ronacher.

Get started with Installation and then get an overview with the Quickstart. This Tutorial will shows how to create a small but complete application with Flask.

Table of Content



Installation

pip install flask


Docs


Why to choose Flask

Flask's framework is more explicit than Django's framework and is also easier to learn because it has less base code to implement a simple web-Application. List of companies using Flask framework - who is using Flask?

Companies using Flask

Minimal app

Code Here

from flask import Flask

app = Flask(__name__)

@app.route("/")
def hello_world():
    return "<p>Hello, World!</p>"

if __name__=="__main__":
    app.run()

So what did that code do?

  1. First we imported the Flask class. An instance of this class will be our WSGI application.

  2. Next we create an instance of this class. The first argument is the name of the application’s module or package. name is a convenient shortcut for this that is appropriate for most cases. This is needed so that Flask knows where to look for resources such as templates and static files.

  3. We then use the route() decorator to tell Flask what URL should trigger our function.

  4. The function returns the message we want to display in the user’s browser. The default content type is HTML, so HTML in the string will be rendered by the browser.


Routing

Code Here

from flask import Flask

app = Flask(__name__)

@app.route('/')
def index():
    return 'This is Index Page'

@app.route('/login')
def login():
    return 'This is Login Page'

@app.route('/hello')
def hello():
    return 'Hello, World'

if __name__=="__main__":
    app.run(debug=True)

Modern web applications use meaningful URLs to help users. Users are more likely to like a page and come back if the page uses a meaningful URL they can remember and use to directly visit a page.

Use the route() decorator to bind a function to a URL.

About

A complete beginner friendly Python Flask tutorial 🐍. Learn from basic template rendering to deploying in web servers.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • HTML 55.7%
  • Python 31.8%
  • CSS 12.5%