Getting Started
Goal for this part
By the end of this snapshot you will have a tiny Flask app that answers one URL with plain text. That sounds small on purpose: web frameworks are easier to learn when you can see the full request path before templates, forms, and databases enter the picture.
Campus Wire starts as a single file named app.py. You create an application object, map the site root to a view function, and return a greeting. Later folders keep this same idea while adding layers around it.
What you should already know
You do not need prior Flask experience. You should be comfortable opening a terminal, running python3, and editing a .py file. Knowing what a function is and how import works will help, but you can learn those pieces as you go.
A virtual environment isolates this project’s packages from the rest of your system. If that idea is new, skim the linked Python lesson on virtual environments before you install anything.
- You can run commands in a terminal
- You know how to save and run a Python file
- Optional: you have used
piporvenvonce before
What Flask is doing for you
A browser sends an HTTP request to a URL. Flask matches that URL to a Python function, runs the function, and turns the return value into an HTTP response. That matching step is called routing.
Without a framework you would write a lot of boilerplate to listen on a port and parse requests. Flask gives you a small, readable way to say: “when someone visits /, call this function.” Understanding that one idea makes every later part easier.
Walkthrough: create the app and a route
Flask(__name__) builds the application object. Passing __name__ helps Flask find resources relative to this module. You almost always create one app object near the top of your entry file.
The @app.route("/") decorator registers the function below it as the handler for the site root. Returning a string sends that text as the response body with a normal HTML content type. The if __name__ == "__main__" block starts the development server only when you run this file directly.
from flask import Flask
app = Flask(__name__)
@app.route("/")
def home():
return "Hello, Blog!"
if __name__ == "__main__":
app.run(debug=True)
How to run it and what you should see
Clone the teaching repo, move into the 01-Getting-Started folder, create a virtual environment, activate it, and install dependencies from the parent requirements.txt. Shared packages live at the repo root so every snapshot can reuse the same list.
Start the app with python app.py. In the terminal you should see Flask’s development server start and a line pointing at http://127.0.0.1:5000/. Open that URL in a browser. The page should show exactly Hello, Blog! with no extra layout yet.
git clone https://github.com/michaeldunga1/fcc-flask-blog.git
cd fcc-flask-blog/01-Getting-Started
python3 -m venv .venv
source .venv/bin/activate
pip install -r ../requirements.txt
python app.py
Common mistakes and troubleshooting
If the browser cannot connect, confirm the terminal still shows the server running and that you used port 5000. If imports fail, make sure the virtual environment is activated and you installed with pip install -r ../requirements.txt from inside the snapshot folder.
Running from the wrong directory is another frequent issue: Flask looks for templates relative to the app later, and installing requirements from the wrong place can leave you with an empty or broken environment. Stay inside 01-Getting-Started for this part.
- Activate the venv before
pip installorpython app.py - Use the parent requirements file:
../requirements.txt - Stop the server with Ctrl+C, then start it again after code changes if needed
Try this
Change the returned string to include your name, save the file, and refresh the browser. With debug=True, Flask often reloads for you; if not, restart the server once.
Then add a second route such as /about that returns a short sentence. Visiting both URLs is a quick check that you understand how decorators map paths to functions—skills you will reuse in every later part.
- One file:
app.py - Shared dependencies live in the repo root
requirements.txt - Confirm http://127.0.0.1:5000/ shows your greeting before moving on
Next: Templates
Comments
One comment per signed-in account. Comments are saved with this page’s URL.