Introduction to Flask and
Web Development
Building your first web application with Python!
Objectives of this Module:
• Understand what Flask is and why it is used.
• Set up a Flask development environment.
• Create a simple Flask web app.
• Run the app locally on your machine.
• Activity: Build and run a basic Flask application.
What is Flask?
Definition: Flask is a lightweight web framework for Python.
Why Use Flask?
• Simple and easy to learn.
• Ideal for small projects and APIs.
• Flexible with extensions for databases, authentication, and more.
Setting Up the Flask Environment
Requirements:
Install Python (latest version).
Install Flask using pip (pip install flask)
Create a virtual environment (python –m venv venv)
Activate the environment and install dependencies.
Tip: Always use a virtual environment to manage dependencies.
Writing Your First Flask App
Steps to Create a Flask App:
Create a new Python file (app.py).
Import Flask.
Define a basic route (/).
Run the Flask application.
Tip: Use debug=True for easier
development.
Running the Flask Application
Steps:
Open a terminal and navigate to the project folder.
Activate the virtual environment.
Run the script using python app.py.
Open http://127.0.0.1:5000 in a browser.
Tip: Use flask run as an alternative command.
Understanding Routes and Views
What are Routes?
Routes define URLs for your web
application.
Example: /about, /contact.
What are Views?
Functions that return responses to a
client request.
Activity Prompt: Add a new route
(/about) to your app.
Activity
Task: Build a simple Flask web app with two routes:
/ (Home page displaying "Hello, Flask!").
/about (Displays "This is the About page.").
Submission: Save your file as YourName_Module1.py and test it locally.
Send to: kingjohnnel.olgado@dyci.edu.ph
Summary
Key Takeaways:
Flask is a lightweight and flexible web framework.
Setting up a Flask project requires Python and pip.
Routes define URLs, and views return responses.
Running app.run(debug=True) starts a local web server.
Next Steps: Learn about Docker and containerizing Flask apps in Module 2.
Introduction to Flask and
Web Development
Building your first web application with Python!