Creating a Basic Flask App in 5 Minutes: A Beginner’s Guide to Python Flask

Posted by


Flask is a lightweight WSGI web application framework for Python that allows you to quickly build web applications. In this tutorial, I will show you how to create a simple Flask app in just 5 minutes.

Step 1: Install Flask
Before we get started, you need to make sure you have Flask installed. You can install Flask using pip, which is the Python package installer. Open your terminal and run the following command:

pip install Flask

Step 2: Create a new Python file
Next, create a new Python file for your Flask app. You can name this file whatever you like, but for this tutorial, let’s name it app.py.

Step 3: Write the code
Open your app.py file and add the following code:

from flask import Flask

app = Flask(__name__)

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

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

In this code, we import the Flask class from the flask module and create a new Flask app instance. We then define a route for the root URL ('/') that returns the string 'Hello, World!'. Finally, we run the app in debug mode.

Step 4: Run the app
To run your Flask app, go back to your terminal and navigate to the directory where your app.py file is located. Then run the following command:

python app.py

You should see output indicating that your Flask app is running. Open your web browser and navigate to http://127.0.0.1:5000/ to see your app in action. You should see the message 'Hello, World!' displayed on the page.

And that’s it! You have successfully created a simple Flask app in just 5 minutes. Feel free to experiment with the code and add more routes or functionality to your app. Flask is a versatile framework that can be used to build a wide variety of web applications, so the possibilities are endless. Happy coding!

0 0 votes
Article Rating

Leave a Reply

28 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@S3CloudHub
20 days ago

Get the FREE COURSES FROM UDEMY

English Courses

GitLab CI: Pipelines, CI/CD, and DevOps for Beginners https://bit.ly/48BGjpq

Infrastructure Automation with Terraform DevOps Tool [2024] https://bit.ly/49fAY7h

Introduction to Linux Shell Scripting https://bit.ly/3ykZROz

AWS Certified Solution Architect Associate [2024] https://bit.ly/47Evamt

Jenkins Tutorial – DevOps : CI/CD with Jenkins | Udemy https://bit.ly/3ix6wdW

Free Ansible Tutorial – Ansible for the Absolute Beginner – DevOps | Udemy https://bit.ly/3RzWMBf

Amazon S3 Mastery Bootcamp https://bit.ly/48E4bbW

AWS Certified SysOps Administrator Associate SOA-C02 [2024] https://bit.ly/4aTJAlz

Free Docker Tutorial – Docker for the Absolute Beginner | Udemy https://bit.ly/3CEgKqk

[2024] Complete Python Bootcamp From Zero to Hero in Python https://bit.ly/3HkkoXI

Hindi Courses

AWS Certified Solution Architect Associate 2024 [HINDI] https://bit.ly/2EpKSu2

Introduction to Linux Shell Scripting in [HINDI] https://bit.ly/3S3x0aF

Terraform ( Infrastructure as Automation ) in Hindi [2024] https://bit.ly/48VR5qh

DevOps : CI/CD with Jenkins in Hindi https://bit.ly/3OtPW1x

Ansible for the Absolute Beginner – DevOps in Hindi | Udemy https://bit.ly/3SHfJTS

Docker for the Absolute Beginner in Hindi https://bit.ly/3MaJNEQ

Free GitLab Tutorial – GitLab CI: Pipelines, CI/CD and DevOps for Beginners Hindi | Udemy https://bit.ly/3ymRjH3

Free Python Tutorial – Python Crash Course For Absolute Beginners in Hindi | Udemy https://bit.ly/3EppC4a

AWS Certified SysOps Administrator Associate SOA-C02 [HINDI] https://bit.ly/3u63adz

@user-me3gl4hm2u
20 days ago

finally something that works!!

@ayankumar2719
20 days ago

Very Helpful, Specially that select interpreter thing !!!!

@ItsRabb
20 days ago

Fake ass comments lmao every comment is in quotes 😂😂😂
Garbage video.
AI generated
Fake and paid comments

@Engr.SharoonHoney
20 days ago

Amazing tutorial in few minutes 😃

@hasinigullapalli4500
20 days ago

I'm not getting python.exe file

@SamuelBlanc-Busin
20 days ago

Thank you so much man ! This video immensely helped !

@thething6268
20 days ago

thanks

@dariusbolos8708
20 days ago

sa mi bag pula in tutorialu tau

@hasinisings0307
20 days ago

thank you for clearing my doubt

@flyonevilwings
20 days ago

BASED

@tugrularslan542
20 days ago

Hey,

I get this error in vscode
"Unable to import 'flask'
my env is activated

whats wrong here ?

@sashikantray5080
20 days ago

superb

@user-xh1jo9zs3m
20 days ago

"Your channel is like a guiding light in the vast sea of IT resources.Thnak you for lighting the way!”

@user-zk2jo8jq6u
20 days ago

Your tutorials have helped me land a job in the tech industry. Thank you for empowering me

@unknownplanet699
20 days ago

Sir !
i am doing a project fake currency detection i done all the code part in jupiter notebook. how i want to integrate with web .
i want to flask so when i use "/test" route then the jupyter notebook file should be displayed (that file contains image uploading and predition happens based on test cases.)

so when user click on "/test" how to display that jupyter file
please help me with it.

@mrsharma_69
20 days ago

"Your dedication to IT education is making a positive impact. Thanks!"

@benjaminwilson9007
20 days ago

On the Windows Operating System, you may have to change the execution policies for the Powershell.

@mr_lolol404
20 days ago

"Your enthusiasm for IT is contagious. Thanks for making learning so much fun!"

@user-yn6dp9lu4t
20 days ago

"Your tutorials are like a breath of fresh air in the world of IT education. Thank you for your dedication!"

28
0
Would love your thoughts, please comment.x
()
x